Hello,
Im a new in mobile development. Im using Visual Studio 2008 plugin and preview tool by default.
I try to call XML file using ajax XMLHttpRequest(), everything is OK in Firefox and IE8. But in Preview tool throws alert with 'Error:0' I spend hours to debug it.
the code in .js file:
.html file:Code:function init() { var url = "xmlNames.xml"; ajaxFetch(url, "", XML_parsing_sequence, 1, 0); // retrieves data from server via ajax function ajaxFetch(url, param, callback, isXML, isPost) { var req = new XMLHttpRequest(); req.onreadystatechange = function() { if (req.readyState == 4 && req.status == 200) { if (isXML && req.responseXML != null) { callback(req.responseXML); } else { callback(null); } } else if (req.readyState == 4 && req.status != 200) { // fetched the wrong page or network error... var err = "Error: " + req.status; alert(err); callback(err); } } if (!isPost) { req.open("GET", url, true); req.send(null); } else { // POST, doesn't work in the emulator! req.open("POST", url, true); req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //req.send("data="+encodeURIComponent(param)); } } function XML_parsing_sequence(xmlFile) { $(xmlFile).find("food").each( function() { alert('asd'); $("#output").append($(this).find("name").text()); //Use the line below, if you have added an attribute to the XML file, e.g. <food id="1"> //$("#output").append($(this).attr("id")+"<br />"); //Add just one extra line in between each tag to form a list $("#output").append("<br>"); }); } }
Info.plistHTML Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Sample Widget</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="basic.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="jquery-1.4.2.min.js"></script> <script type="text/javascript" src="basic.js"></script> <meta name="generator" content="Nokia WRT extension for Visual Studio 2.0" /> </head> <body onload="init()"> <div id="output" align="center"> </div> </body> </html>
.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Nokia//DTD PLIST 1.0//EN" "http://www.nokia.com/DTDs/plist-1.0.dtd"> <plist version="1.0"> <dict> <key>DisplayName</key> <string>ovitop5</string> <key>Identifier</key> <string>com.ovitop5.basic.widget</string> <key>MainHTML</key> <string>index.html</string> <key>AllowNetworkAccess</key> <true/> <key>Version</key> <string>1.0</string> <key>MiniViewEnabled</key> <true/> </dict> </plist>attached screenshotHTML Code:<?xml version="1.0" encoding="utf-8" ?> <breakfast_menu> <food> <name>Belgian Waffles</name> <price>$5.95</price> <description> two of our famous Belgian Waffles with plenty of real maple syrup </description> <calories>650</calories> </food> <food> <name>Strawberry Belgian Waffles</name> <price>$7.95</price> <description> light Belgian waffles covered with strawberries and whipped cream </description> <calories>900</calories> </food> <food> <name>Berry-Berry Belgian Waffles</name> <price>$8.95</price> <description> light Belgian waffles covered with an assortment of fresh berries and whipped cream </description> <calories>900</calories> </food> <food> <name>French Toast</name> <price>$4.50</price> <description> thick slices made from our homemade sourdough bread </description> <calories>600</calories> </food> <food> <name>Homestyle Breakfast</name> <price>$6.95</price> <description> two eggs, bacon or sausage, toast, and our ever-popular hash browns </description> <calories>950</calories> </food> </breakfast_menu>![]()

Reply With Quote

