Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User a.sichel's Avatar
    Join Date
    Aug 2008
    Posts
    1
    Hello everybody,
    i'm new in this forum and also in the development of S60 widgets.

    I'm trying to execute an XMLHttpRequest from my widget(tested on the RDA service with a Nokia N95 8gb) and I don't obtain the expected results.

    This is the simple code of my request:

    var req;

    function getXHR()
    {
    req = null;
    try {
    req = new XMLHttpRequest();

    } catch (ex) {
    req = null;
    }

    return req;
    }


    function getResp()
    {
    if(getXHR())
    {

    req.onreadystatechange = function()
    {
    if(req.readyState == 4) {
    if(req.status == 200) {
    document.getElementById('mainView').innerHTML = "<h4>"+req.responseText+"</h4>";
    }
    else
    document.getElementById('mainView').innerHTML = "<h4>"+req.status+"</h4>";
    }


    }


    req.open('GET', 'http://testwidget.site40.net/counter.php', false);
    req.send(null);
    }

    }


    I just created this simple code to visualize if the widget works correctly.

    The N95 visualizes the value "undefined".

    I have seen in many page of this forum if there were some suggestions but I didn't find anything...

    I hope that someone could help me.

    Thanks a lot, Andrea

  2. #2
    Regular Contributor Bernd42's Avatar
    Join Date
    Jan 2004
    Location
    Braunschweig, Germany
    Posts
    345
    I have a similar problem:

    GET is working fine. I get the content, readyState is as expected and status is 200.

    POST is also kind of working, but the status value always is undefined but in the http monitor the status from the server is 201.

    I tested the widget on an E90 and it is exactly the same on the device.

    Any ideas about this?

    Bernd

  3. #3
    You can also use prototype.js framework for handling ajax and other functions for javascript.
    Regards,

    Ravindra Suthar

  4. #4
    Regular Contributor ferranhalden's Avatar
    Join Date
    Jan 2004
    Posts
    128
    any updates about this issue..thanks

  5. #5
    Registered User mfabiop's Avatar
    Join Date
    Mar 2007
    Location
    ..., Earth, Brazil, Paraiba, Campina Grande
    Posts
    58
    In this line:

    Code:
    req.open('GET', 'http://testwidget.site40.net/counter.php', false);
    When the last parameter is 'false', the 'open' method is a synchronous call. The 'readyonstatechange' function will never happen. Try to put an 'alert' inside it to test.

    I think the solution is to change the last parameter to 'true', then the 'open' method will be an asynchronous call and it should work.

  6. #6
    Regular Contributor ferranhalden's Avatar
    Join Date
    Jan 2004
    Posts
    128
    I found the following note in Internet

    <Observation> The reason for using the 402 status-code instead of 401 is that Opera and Safari do not pass the 401 status-code back to the application if they do not understand the authentication mechanism. Alternatively, an undefined code like 418 could be used. </Observation>

    My problem was related that I cant get the content body when a 401 response is gotten. So I am afraid this is the behavior of webkit.

  7. #7
    Regular Contributor Bernd42's Avatar
    Join Date
    Jan 2004
    Location
    Braunschweig, Germany
    Posts
    345
    Quote Originally Posted by mfabiop View Post
    In this line:

    Code:
    req.open('GET', 'http://testwidget.site40.net/counter.php', false);
    When the last parameter is 'false', the 'open' method is a synchronous call. The 'readyonstatechange' function will never happen. Try to put an 'alert' inside it to test.

    I think the solution is to change the last parameter to 'true', then the 'open' method will be an asynchronous call and it should work.
    I used the version of the method without the boolean parameter and this is asynchronous. The onreadystatechange function gets called, but the req.status is set to undefined but should contain a value.

    Bernd

  8. #8
    Registered User mfabiop's Avatar
    Join Date
    Mar 2007
    Location
    ..., Earth, Brazil, Paraiba, Campina Grande
    Posts
    58
    The widget will only get a HTTP status if the server send it back to the widget after a request. You can test the server executing a 'telnet url port', then a GET command. See if the server returns a HTTP status.

    MF

  9. #9
    Regular Contributor Bernd42's Avatar
    Join Date
    Jan 2004
    Location
    Braunschweig, Germany
    Posts
    345
    Well, I tested it in a Web Page before and then used the same JavaScript code in the Widgets and used exactly the same web server. I got an HTTP status in the browser but none in the Widget, so I assume that it is not a problem with the server.

    Bernd

  10. #10
    Registered User mfabiop's Avatar
    Join Date
    Mar 2007
    Location
    ..., Earth, Brazil, Paraiba, Campina Grande
    Posts
    58
    Very strange... Could you show the code?

  11. #11
    Registered User asdf23's Avatar
    Join Date
    Apr 2008
    Posts
    2
    Quote Originally Posted by mfabiop View Post
    Very strange... Could you show the code?
    Hi ,
    I too am getting the same error: This is on the Aptana emulator.
    status = 200
    state = undefined


    <html>
    <head>
    <title> Sample Widget</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script language="javascript" type="text/javascript" src="basic.js"></script>
    <style type="text/css">
    @import "basic.css";
    </style>
    <META NAME="Generator" CONTENT="Nokia WRT plug-in for Aptana Studio 1.0.0.36" />
    </head>
    <body onLoad="javascript:init();">
    </body>
    </html>


    /*
    * JavaScript file
    */

    var socialLight;
    function Soc()
    {
    socialLight = new XMLHttpRequest();
    return socialLight;
    }
    function init()
    {
    socialLight = new Soc();
    alert("init");

    var url = "http://socialight.com"

    alert("ON READY CHANGE");
    socialLight.onreadystatechange = function()
    {

    alert("readystate = "+ socialLight.readystate);
    alert("status = "+ socialLight.status);


    if(socialLight.readystate == 4 && socialLight.status == 200)
    alert("SUCCESS");
    else
    alert("Error");
    }

    alert("GET");
    socialLight.open("GET", url, true);

    alert("SEND");
    socialLight.send(null);
    }

  12. #12
    Nokia Developer Champion jappit's Avatar
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,391
    Hi asdf23,

    you're mistyping the readyState property name, that in your code is written without the uppercase 'S', for example in this line:
    Code:
    alert("readystate = "+ socialLight.readystate);
    Hope it helps,
    Pit

  13. #13
    Registered User asdf23's Avatar
    Join Date
    Apr 2008
    Posts
    2
    Quote Originally Posted by jappit View Post
    Hi asdf23,

    you're mistyping the readyState property name, that in your code is written without the uppercase 'S', for example in this line:
    Code:
    alert("readystate = "+ socialLight.readystate);
    Hope it helps,
    Pit
    Hi jappit,

    Thanks... That indeed was the mistake..

Similar Threads

  1. [moved] HELP! Phone Debug (GCCE)
    By joseph.m in forum Symbian C++
    Replies: 18
    Last Post: 2008-07-14, 10:42
  2. mwldsym2.exe: Undefined symbol in Carbide.C++ 1.3
    By ValentinK in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 4
    Last Post: 2008-03-14, 15:23
  3. carbide c++ can't find headers.!!
    By nokia_maniac in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 29
    Last Post: 2007-12-19, 12:54
  4. illegal use of abstract class error...
    By kannabiran.krish in forum Symbian C++
    Replies: 7
    Last Post: 2007-08-17, 10:11
  5. file not found
    By praktikant in forum Symbian C++
    Replies: 16
    Last Post: 2007-05-09, 15:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved