×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    63

    XMLHttpRequest status always returns NULL

    Hello,

    I have modified the RSS Feeder created using aptana to get the feeds from twitter. My problem is if i run the application on Nokia WRT environment, it is working perfectly fine. But if i test on phone, status of XMLHttpRequest object always returns NULL but in emulator it returns 200.

    Also i could notice that in emulator it takes ~30 seconds to hit my callback function but in phone it hits my callback immediately.


    this.httpReq = new XMLHttpRequest();
    var self = this;
    this.httpReq.onreadystatechange = function() { self.readyStateChanged(); };

    var fullURL = feedURL;
    alert("fullurl " +fullURL);
    this.httpReq.open("GET", fullURL, true);
    this.httpReq.send(null);

  2. #2
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    103

    Re: XMLHttpRequest status always returns NULL

    hello

    plz use that code:

    var ajaxGet = null;
    ajaxGet = new XMLHttpRequest();
    ajaxGet.open("GET", url, true);
    ajaxGet.onreadystatechange = function()
    {//Call a function when the state changes.
    if(ajaxGet.readyState == 4 )
    {
    if(ajaxGet.status==200)
    {
    var aa = ajaxGet.responseText;
    }
    }
    }
    ajaxGet.send(null);


    Tarun(TJ)

  3. #3
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    63

    Re: XMLHttpRequest status always returns NULL

    Thanks tarun. Mistake was from my side.

    While hardcoding the URL i missed "http://". Instead of hardcoding it as "http://google.com" i have hardcoded as "google.com"

    Now i have added and it works fine (wasted 6 hrs)

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    1

    Re: XMLHttpRequest status always returns NULL

    Does anyone know why I am getting XMLHttpRequestObject.status = 0 ? what does it mean. I am trying to create rss reader widget. Status is always zero. XMLHttpRequestObject.responseXML is always null. Please help me =(


    Here's the FeedUpdateBroker.js from the sample downloaded from nokia site.
    feedURL is "http://feeds.feedburner.com/N95"

    function FeedUpdateBroker() {
    this.httpReq = null;
    this.callback = null;
    }

    // Fetches a feed from the specified URL and calls the callback when the feed
    // has been fetched and parsed, or if the process results in an error.
    FeedUpdateBroker.prototype.fetchFeed = function(feedURL, callback) {
    // remember callback
    this.callback = callback;

    // create new XML HTTP request
    this.httpReq = new Ajax();

    // set callback
    var self = this;
    this.httpReq.onreadystatechange = function() { self.readyStateChanged(); };

    // append the current time after the URL to bypass caches
    var fullURL = feedURL;
    if (fullURL.indexOf("?") == -1) {
    fullURL += "?";
    } else {
    fullURL += "&";
    }
    fullURL += "nocache=" + (new Date().getTime());

    // initiate the request
    alert('this.httpReq.open');
    this.httpReq.open("GET", fullURL, true);
    //this.httpReq.open("GET",'http://www.mozilla.org',false);
    alert('this.httpReq.open successful');
    //this.httpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
    this.httpReq.overrideMimeType('text/xml');
    this.httpReq.send(null);
    }

    // Callback for ready-state change events in the XML HTTP request.
    FeedUpdateBroker.prototype.readyStateChanged = function() {
    // complete request?
    alert('readyStateChanged');
    alert('this.httpReq.readyState: ' + this.httpReq.readyState);
    if (this.httpReq.readyState == 4) {
    // attempt to get response status
    var responseStatus = null;
    try {
    responseStatus = this.httpReq.status;
    // if (responseStatus == 200){
    alert('this.httpReq.readyState: ' + this.httpReq.readyState);
    alert('this.httpReq.StatusText: ' + this.httpReq.StatusText);
    alert('try responseStatus: ' + responseStatus);//}
    } catch (noStatusException) {}

    // handle the response and call the registered callback
    this.callback.call(this, this.handleResponse(responseStatus, this.httpReq.responseXML));
    }
    }

    // Handles a completed response.
    FeedUpdateBroker.prototype.handleResponse = function(responseStatus, xmlDoc) {
    if (responseStatus == 200 && xmlDoc != null) {
    // node ref for iterating
    var node;

    // get last modified time - default to current time
    var lastModified = new Date().getTime();
    var channelElements = xmlDoc.getElementsByTagName("channel");
    if (channelElements.length > 0) {
    node = channelElements[0].firstChild;
    while (node != null) {
    if (node.nodeType == Node.ELEMENT_NODE) {
    if (node.nodeName == "pubDate" ||
    node.nodeName == "lastBuildDate" ||
    node.nodeName == "dc:date") {
    lastModified = this.getTextOfNode(node);
    break;
    }
    }
    node = node.nextSibling;
    }
    }

    // init feed items array
    var items = [];

    // we got the feed XML so now we'll parse it
    var itemElements = xmlDoc.getElementsByTagName("item");
    for (var i = 0; i < itemElements.length; i++) {
    // iterate through child nodes of this item and gather
    // all the data we need for a feed item
    var title = null;
    var date = null;
    var description = null;
    var url = null;

    node = itemElements[i].firstChild;
    while (node != null) {
    if (node.nodeType == Node.ELEMENT_NODE) {
    if (node.nodeName == "title") {
    // item title
    title = this.getTextOfNode(node);
    } else if (node.nodeName == "pubDate" || node.nodeName == "dc:date") {
    // item publishing date
    date = this.getTextOfNode(node);
    } else if (node.nodeName == "description") {
    // item description
    description = this.getTextOfNode(node);
    } else if (node.nodeName == "link") {
    // link URL
    url = this.getTextOfNode(node);
    }
    }
    node = node.nextSibling;
    }

    // create the item and add to the items array
    items.push({ title: title, date: date, description: description, url: url });
    }

    // update was completed successfully
    return { status: "ok", lastModified: lastModified, items: items };
    } else {
    // update failed
    return { status: "error" };
    }
    }

    // Returns the text of a node.
    FeedUpdateBroker.prototype.getTextOfNode = function(node) {
    var buf = "";

    // iterate through all child elements and collect all text to the buffer
    var child = node.firstChild;
    while (child != null) {
    if (child.nodeType == Node.TEXT_NODE || child.nodeType == Node.CDATA_SECTION_NODE) {
    // append text to buffer
    if (buf != "") {
    buf += " ";
    }
    buf += child.nodeValue;
    }
    child = child.nextSibling;
    }

    // strip all tags from the buffer
    var strippedBuf = "";
    var textStartPos = -1;
    var tagBalance = 0;

    // iterate through the text and append all text to the stripped buffer
    // that is at a tag balance of 0
    for (pos = 0; pos < buf.length; pos++) {
    var c = buf.charAt(pos);
    if (c == '<') {
    // entering a tag
    if (tagBalance == 0 && textStartPos != -1) {
    // everything up to here was valid text
    strippedBuf += buf.substring(textStartPos, pos);
    textStartPos = -1;
    }
    tagBalance++;
    } else if (c == '>') {
    // leaving a tag
    tagBalance--;
    textStartPos = -1;
    } else if (tagBalance == 0 && textStartPos == -1) {
    // first char of text
    textStartPos = pos;
    }
    }

    // add remaining text - if any
    if (tagBalance == 0 && textStartPos != -1) {
    strippedBuf += buf.substring(textStartPos, pos);
    }

    return strippedBuf;
    }
    Last edited by bbernabe; 2009-09-11 at 04:44. Reason: insufficient info

  5. #5
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    63

    Re: XMLHttpRequest status always returns NULL

    I don't see any problem with the URL you mentioned. I created a RSS feeder in Aptana using that URL and it worked very well.

  6. #6
    Registered User
    Join Date
    Feb 2009
    Posts
    19

    Re: XMLHttpRequest status always returns NULL

    I noticed that sometimes I get XMLHttpRequestObject.status = 0 when debugging with Firefox. But in real device the same code is working fine.

  7. #7
    Registered User
    Join Date
    Sep 2009
    Posts
    16

    Re: XMLHttpRequest status always returns NULL

    i had issues like that too, looks like former code malfunctions within the javascript code, which do NOT leed to an exception directly, influence the httpRequest behavior. Then you get XMLHttpRequestObject.status = 0. You will notice that the readyState of the RequestObject will change from 1 to 2 to 4 and never be 3 within the request sequence.

    edit: this is really bad i have the error again and this time i cant find the bug *_* i even got the hole requesttext but the status status is still 0
    Last edited by Äpfel; 2009-09-25 at 09:11.

Similar Threads

  1. javax.microedition.io.ConnectionNotFoundException: couldn't open socket
    By sj_incognito in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2009-06-11, 12:40
  2. MFStandardConnection.getApplicationDirectory returns null
    By valenj4 in forum Near Field Communication
    Replies: 2
    Last Post: 2009-05-12, 18:36
  3. Video playback with sound but nothing on Screen
    By abdullah829 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 5
    Last Post: 2007-11-30, 14:04
  4. Connection problem with Nokia 6681.
    By hadhi631 in forum Mobile Java Networking & Messaging & Security
    Replies: 8
    Last Post: 2006-09-08, 21:45

Posting Permissions

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