×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    18

    XMLHttpRequest in Nokia Browser

    Hi..!!
    I am having problems trying to get a XMLHttpResponse from a page... I had a code that works perfectly at Ovi Browser, but then comes the latest actualization "Nokia Browser" and now it doesn't works like before...
    I'm gonna write my function here:

    function getjson(){
    var xhr;
    var url = 'http://feed.finsat.com.mx/movilesV2/feedindicadores.asp';
    var pincel = '';

    //call the right constructor for the browser being used
    if (window.ActiveXObject) {
    //xhr = new ActiveXObject("Microsoft.XMLHTTP");
    try {
    xhr = new ActiveXObject("MSXML2.XMLHTTP");
    } catch (e) {
    try {
    xhr = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
    }
    }
    else
    if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
    }
    else {
    pincel += 'AJAX request not supported';
    }

    xhr.open("GET", url, false);
    xhr.setRequestHeader("Cache-Control", "no-cache");
    xhr.setRequestHeader("Pragma", "no-cache");
    xhr.onreadystatechange = function(){
    if (xhr.readyState == 4) {
    if (xhr.status == 200) {
    if (xhr.responseText != null) {
    pincel += xhr.responseText;
    }
    else {
    pincel+='Failed to receive RSS file from the server - file not found.';
    return false;
    }
    }
    else {
    pincel += "Error code " + xhr.status + " received: " + xhr.statusText;
    }
    }
    }
    xhr.send(null);
    document.getElementById('Noticias').innerHTML=pincel;
    }

    I am just trying to print the textResponse on a Div, and it works over the simulator, but it doesn't works at the nokia Browser in Device, and also It worked before the actualization on Ovi Browser...
    Does anybody have a solution for this problem...??
    Thanks in advance...
    Chelix

  2. #2
    Nokia Developer Moderator
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: XMLHttpRequest in Nokia Browser

    Hi,

    Your code sort of works. It will get the response back correctly but the text just won't be displayed on the device screen.

    What you could do is to make GET request asynchronous xhr.open("GET", url, true); and modify the rest of the code to work in asynchronous way.
    In addition you could get rid of the IE related xhr stuff at the beginning as it is not needed.

    Br,
    Ilkka

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    18

    Re: XMLHttpRequest in Nokia Browser

    Quote Originally Posted by isalento View Post
    Hi,

    Your code sort of works. It will get the response back correctly but the text just won't be displayed on the device screen.

    What you could do is to make GET request asynchronous xhr.open("GET", url, true); and modify the rest of the code to work in asynchronous way.
    In addition you could get rid of the IE related xhr stuff at the beginning as it is not needed.

    Br,
    Ilkka
    Hi Ilkka...!!!
    Thanks for your answer... My code is actually working on emulator... Besides I've written a simplier function.. Just to get the responseText.. Here the code:

    Code:
    function getJSON(){
    	var xhr;
    	xhr = new XMLHttpRequest();
    	xhr.open("GET", 'http://feed.finsat.com.mx/movilesV2/feedindicadores.asp', true);
    	xhr.onreadystatechange = function(){
    		if (xhr.readyState == 4) {
    			if (xhr.status == 200) {
    				document.getElementById('Noticias').innerHTML= xhr.responseText;
    			}
    			else {
    				document.getElementById('Noticias').innerHTML= "Error code " + xhr.status;
    			}
    		}
    	}
        xhr.send(null);
    }
    It still worknig on emulator, and shows me the JSON that I want... But running the same application at Nokia Browser by url shortener it returns me an Error code 0...
    Perhaps is a bug on Nokia Browser... It worked before the last actualization... :S
    Last edited by Chelix; 2011-07-19 at 23:02.

  4. #4
    Nokia Developer Moderator
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: XMLHttpRequest in Nokia Browser

    Hi,

    That looks good. I don't know why the device won't render the plain JSON response to the screen anymore. Anyhow the next step is to refine the data to be displayed.

    In this code plain eval is used, but you might want to use some dedicated parsing script to make Web App more robust & secure.

    Code:
     ...
     if (xhr.status == 200) {				
       parse(xhr.responseText);
     }
    ...
    
    function parse(responseText){
    
        var obj = eval('(' + responseText + ')');
      
        var text = "";
        
        for (var i = 0; i < obj.ResultSet.Result.length; i++) {
            var result = obj.ResultSet.Result[i];
    		
            text += result.categoria +"<br>";
           
        }
        
        document.getElementById("noticias").innerHTML = text;
    }
    -Ilkka

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    18

    Re: XMLHttpRequest in Nokia Browser

    Thanks Ilkka... I already have a parseJSON function, but It won't work if I can't get the responseText of the XMLHttpRequest

    I really need some help here...!!! :S
    Last edited by Chelix; 2011-07-19 at 22:58.

  6. #6
    Regular Contributor
    Join Date
    Jun 2010
    Posts
    161

    Re: XMLHttpRequest in Nokia Browser

    Have you checked http://www.developer.nokia.com/info/..._App_Qype.html ?
    It should help!

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    18

    Re: XMLHttpRequest in Nokia Browser

    Quote Originally Posted by lorion84 View Post
    Thanks for your answer lorion84... I tried to make the example.. In emulator it works.. I can see the list of countries.. But when I deploy and try to see the app at the Nokia Browser, happens the same problem, I can't see the list, I guess that the problem is at the XMLHtttprequest, it doesn't send the JSON response...
    I have done the RSSReader example too, but neither it works... The XMLHttpRequest doesn't send response...
    I have updated the firmware version of my Nokia X-3 02 Now I have V 06.00, and still doesn't works...!!!
    Does anybody made works a simple example of this...??? I don't know if is a code mistake or a bug of Nokia Browser... Please Help...

  8. #8
    Registered User
    Join Date
    Jun 2011
    Posts
    18

    Re: XMLHttpRequest in Nokia Browser

    Am I the only one who is experiencing this kind of problem...???

  9. #9
    Nokia Developer Moderator
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: XMLHttpRequest in Nokia Browser

    Hi,

    Well that sounds really strange.
    What Browser version do you have installed at the moment? (Menu - > Tools -> About) and have you tested to reinstall the browser?

    -Ilkka

  10. #10
    Registered User
    Join Date
    Jun 2011
    Posts
    18

    Re: XMLHttpRequest in Nokia Browser

    Quote Originally Posted by isalento View Post
    Hi,

    Well that sounds really strange.
    What Browser version do you have installed at the moment? (Menu - > Tools -> About) and have you tested to reinstall the browser?

    -Ilkka
    Hi Isalento..!!

    The browser version that I am using is 1.0.3.23.12, and yes, I have reinstalled the browser about 3 times... Do you have any idea of what is happening..?? Thanks in advance...

    Regards..

    Chelix

  11. #11
    Nokia Developer Moderator
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: XMLHttpRequest in Nokia Browser

    Hi Chelix,

    I'm terribly sorry I forgot to get back to you. The issue you experienced was most likely due to use of a Beta version of Ovi Browser. Current version is Nokia browser is 1.5.0.34.15 and that should be used in development.

    http://download.browser.ovi.com/

    Br,
    Ilkka

Similar Threads

  1. Network Unavailable in QML with XMLHttpRequest
    By BrettQ in forum [Archived] Qt Quick
    Replies: 0
    Last Post: 2011-04-17, 19:30
  2. I have a problem with XMLHttpRequest in JS
    By DaParadoks in forum Symbian
    Replies: 1
    Last Post: 2011-03-19, 14:05
  3. Replies: 5
    Last Post: 2010-08-17, 10:34
  4. Replies: 2
    Last Post: 2010-06-01, 17:21
  5. nokia 7250I cant see anything in nokia browser
    By cmfugen in forum General Development Questions
    Replies: 2
    Last Post: 2008-09-23, 11:57

Posting Permissions

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