×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    5

    WRT Preview alerting Error:0 for XMLHttpRequest req.send(null)

    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:
    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>");
            });
        }
    }
    .html file:
    HTML 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>
    Info.plist
    Code:
     <?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>
    .xml
    HTML 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>
    attached screenshot

  2. #2
    Regular Contributor
    Join Date
    May 2009
    Location
    sydney
    Posts
    117

    Re: WRT Preview alerting Error:0 for XMLHttpRequest req.send(null)

    add a line of code
    Code:
    netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
    before your httpxmlrequest should solve your problem
    Nokia is back!

Similar Threads

  1. XMLHttpRequest status always returns NULL
    By vinothg in forum Symbian
    Replies: 6
    Last Post: 2009-09-22, 09:22
  2. m-send-req & m-retrieve-conf
    By tlindstr in forum General Messaging
    Replies: 2
    Last Post: 2003-06-27, 12:15
  3. M-send-req Pdu
    By fix78 in forum General Messaging
    Replies: 0
    Last Post: 2003-05-07, 16:31
  4. question about M-Send.req
    By homanshing in forum General Messaging
    Replies: 1
    Last Post: 2002-11-19, 05:24
  5. M-Send-Req message encoding
    By muralimohank in forum General Messaging
    Replies: 1
    Last Post: 2002-08-19, 05:56

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×