×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    9

    Simple AJAX Request fails on real Series 40 Phone - Nokia Asha 311

    I'm having some issues doing a simple AJAX Request in a Nokia Asha 311 (actual phone).

    The following is my Javascript code:

    Code:
    $.ajax({
    	type: "GET",
    	url: "http://myurl",
    	headers: {
    		"Cache-Control":"no-cache",
    		"Pragma":"no-cache"
    	},
    	success: function(response) {
    		$("#mydiv").text("Yes!");
    	},
    	error: function(){
    		$("#mydiv").text("No!");
    	}
    });
    When I use this in the Nokia Emulator on my PC, I see "Yes!". However, on the real device I see "No!".

    How come it's working on an emulator and not on the phone?! What can I do to remedy this anomaly?!

    Thanks.

    P.S. From the phone settings I see that the browser is Version 2.3.0.0.49.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,697

    Re: Simple AJAX Request fails on real Series 40 Phone - Nokia Asha 311

    Assuming that your question is in the context of this board, note that Series 40 Web Apps are running on a server, with the single exception of the local-preview-in-emulator case. See http://www.developer.nokia.com/Commu...p_Simulator.3F. There are many limitations about JavaScript, you can find some of them listed a bit below in the article.

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    9

    Re: Simple AJAX Request fails on real Series 40 Phone - Nokia Asha 311

    Ok, after fiddling with multiple variations of code, I finally figured this out.

    It appears that there is something going on with the way URLs are being processed on the Proxy-Server-side of the Nokia Xpress browser.

    When I tried the following code, it doesn't work:

    Code:
    var xhr = new XMLHttpRequest();
    var myurl = "http://logme.mobi/js.text"; 
    xhr.onreadystatechange = function() {
           if (xhr.readyState == 4 && xhr.status == 200) {
    	     $("#djs_ua_proxy").text(xhr.responseText);
           }
    };
    xhr.open('GET', myurl, true);
    xhr.setRequestHeader("Cache-Control", "no-cache");
    xhr.setRequestHeader("Pragma", "no-cache");
    xhr.send(null);
    However, when I created my own server to echo the User Agent, it works ok:

    Code:
    var xhr = new XMLHttpRequest();
    var myurl = "http://www.mydomain.com/ua/index.php"; 
    xhr.onreadystatechange = function() {
           if (xhr.readyState == 4 && xhr.status == 200) {
    	     $("#djs_ua_proxy").text(xhr.responseText);
           }
    };
    xhr.open('GET', myurl, true);
    xhr.setRequestHeader("Cache-Control", "no-cache");
    xhr.setRequestHeader("Pragma", "no-cache");
    xhr.send(null);
    One thing to notice is that if you provide a URL without the hostname i.e. http://mydomain.com as opposed to http://www.mydomain.com, the script will not work.

    I don't know what is happening server-side at Nokia, but I think they should probably look into it.

    Cheers.

  4. #4
    Regular Contributor
    Join Date
    Mar 2005
    Location
    Hamburg, Germany
    Posts
    284

    Re: Simple AJAX Request fails on real Series 40 Phone - Nokia Asha 311

    The proxy server does not follow redirects automatically.
    Sometimes the server administrator let mydomain.com redirects to www.mydomain.com, (sometimes the other way around)
    Also often there is a redirect from mydomain.com/dir to mydomain.com/dir/ or mydomain.com/dir/index.php

    See the list of known issues:
    http://www.developer.nokia.com/Commu...-_known_issues
    "XMLHttpRequest fails to follow HTTP 302 Redirect "

    You should see this behaviour also when you use the cloud preview in your emulator. There you can debug better than on the phone.

    Regards

    Karsten Meier

Similar Threads

  1. AJAX Request is different from what is set.
    By bernardnapoleon in forum Nokia Asha Web Apps
    Replies: 2
    Last Post: 2012-05-08, 10:11
  2. Listening HTTP AJAX request
    By condorx in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2009-11-02, 18:37
  3. Game runs in a series 60 emulator but fails on a real 3650
    By bobfin in forum Mobile Java General
    Replies: 3
    Last Post: 2003-10-17, 09:44
  4. Replies: 1
    Last Post: 2002-05-16, 19:08

Posting Permissions

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