×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    4

    Problem: Javascript running while selecting network

    Hi forum nokia people,

    i am trying to solve this problem, it goes like this..

    i got a program that requires me to go online and collect data from the server. at the point when i use Ajax xmlHttpRequest to go online, the widget naturally will prompt the WINSOCK, or prompt you to connect using wireless or gprs for network.

    At the same point of time, before i had select the wireless network and go online, the Javascript is still running. I wanted to halt the javascript at the point when it prompt to select the network to use and continue the javascript from that point of time after i selected the network.

    for e.g. program like this

    A program which request and fetch a variable A from the server to the widget, the widget Add A + 5 and display the result.

    So if A is 5, the result would be 10.

    but when the part where fetching the variable A from servers requires the handset to choose network whether wireless or 3G/GPRS to go online,at that point of time the javascript behind already finish running and gave the result as "null" + 5 before i finish selecting the network.

    i am not sure how to solve, or has to halt the javascript,
    i have tried delay function but in vain

    Any suggestion for my problem?

    Thank you for your kind attention and reply !

  2. #2
    Nokia Developer Expert
    Join Date
    Oct 2008
    Posts
    9

    Re: Problem: Javascript running while selecting network

    Hi shixiong,

    If I understood your problem correctly, your program work like this.

    Code:
    // Ajax request to get the value from Internet server
    A = getValueFromServer();
    
    // continue add
    sum = A + 5;
    Ajax requests are Asynchronous, so JavaScript statement execution will not be in hold till the function call gets the value from the server.
    So, do your addition step/statements will be called when you'll get the ajax response from the server.

    Ajax request
    Code:
    function getValueFromServer() 
    {
    	var req = new XMLHttpRequest();
    	req.onreadystatechange = processReqChange;
    	req.open("GET", url, true);
    	req.send(null);
    }
    
    function processReqChange() 
    {
         if (req.status == 200) {
                continueYourExecutionHere();
            }
    }
    
    function continueYourExecutionHere()
    {
          sum = A + 5;
    }

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    4

    Angry Re: Problem: Javascript running while selecting network

    I still think that there should be a way to block the execution WHILE the user is choosing a connection.

    My problem is similar to the above, except that what I am implementing is a timeout for the request. What happens is that it takes quite a while for the user to allow and select a connection and this time also varies a lot between users. The only workaround is to set a timeout so long that it is almost useless.

    Ideally, there should be a widget method to request a connection that returns when the user has done that (with the result of true or false depending on what the user did). After that, if you got confirmation from the user, you can use the same connection as you would with standard httprequest calls.

    Christian

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,405

    Re: Problem: Javascript running while selecting network

    Hi Christian,

    I faced a similar "problem" with connection timeouts from within a Flash Lite application. Having a callback called when the IAP is chosen would be useful in such a case but, personally, I think It'll be quite hard to have it implemented somewhere in the future

    Pit

Similar Threads

  1. network problem on 6111
    By superjean in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2007-06-15, 12:11
  2. Urgent :problem while running HTTPS in J2me for Nokia 3250
    By ratan_java_me in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2007-05-02, 17:45
  3. nokia 6280 network problem
    By mustaqtvpm in forum General Development Questions
    Replies: 1
    Last Post: 2007-04-24, 05:04
  4. problem with connecting socket between phone and midlet running on a PC
    By weiyou in forum Symbian Networking & Messaging (Closed)
    Replies: 19
    Last Post: 2007-02-14, 06:09
  5. problem in running application on device
    By vinod_shelke in forum Symbian
    Replies: 1
    Last Post: 2004-04-12, 04:28

Posting Permissions

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