×

Discussion Board

Results 1 to 1 of 1
  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    1

    QML + XmlHttpRequest

    Hi guys,
    I'm completely fresh to Nokia/QT development.
    I have stumbled upon the following problem:

    Let's say I have Qt Quick app with only one button and a text field for logs.
    Pressing this button launches JavaScript function with the following code:

    Code:
    function getToken() {
        var response  = "";
    
        var http = new XMLHttpRequest();
        http.onreadystatechange = function()
            {
                response += http.readyState.toString() + "\n";
    
                if (http.readyState == 4)
                {
                    response = "Data has been sent\n";
    
                    if (http.status == 200)
                    {
                        response += http.responseText + "\n";
                    }
                    else
                    {
                        response += "Response error\n" + http.status;
                    }
                }
            }
    
        http.open("GET", "http://www.bez-kabli.pl"); //or whatever www site
        http.send(null);
    
        text_edit1.text = response;
    }
    The problem is that the only thing I get in log is state "1", so connection is made and XmlHttpRequest object is stuck on this state.
    I run this app on Nokia Simulator. The site in url is working ok, computer is connected via router w/NAT (no proxy). Router firewall monitoring is clearly stating that connection is made.
    I tried with POST, but same result.

    Any ideas where I went wrong? How could I debug this?


    best regards


    EDIT:

    I got it to work... sort of

    Now it looks like this (I split it into modules to make debug easier and added some exception handling):

    Code:
    var http = null;
    var response  = "";
    
    function getResponse()
    {
        try
        {
            if (http.readyState == 4)
            {
                response = "Your data has been sent\n";
    
                if (http.status == 200)
                {
                    response += http.responseText + "\n";
                }
                else
                {
                    response += "Response error\n" + http.status;
                }
            }
        }
        catch (e)
        {
            response += "getResponse() error:" + e;
        }
    }
    
    function getToken() {
        try
        {
            http = new XMLHttpRequest();
            http.onreadystatechange = getResponse;
    
            http.open("GET", "http://www.bez-kabli.pl");
            http.setRequestHeader("Connection", "close");
            http.send();
        }
        catch (e)
        {
            response += "getToken() error:" + e;
        }
        text_edit1.text = response;
    }
    The "sort of" part is that I click the button once - nothing, I click it again - and there it is (whole HTML page code). A little confusing for me.
    Last edited by jo_gurt; 2013-01-02 at 18:00.

Similar Threads

  1. I have a problem with XMLHttpRequest in JS
    By DaParadoks in forum Symbian
    Replies: 1
    Last Post: 2011-03-19, 14:05
  2. QtScript + XMLHttpRequest
    By gurmukh in forum Nokia N9
    Replies: 9
    Last Post: 2010-08-25, 11:55
  3. XMLHTTPREQUEST
    By yynneejj in forum Symbian
    Replies: 7
    Last Post: 2010-06-08, 14:55
  4. Synchronous xmlHttpRequest
    By strider2k in forum Symbian
    Replies: 3
    Last Post: 2009-12-21, 11:29
  5. XMLHttpRequest problem
    By kogan_y in forum Symbian
    Replies: 3
    Last Post: 2009-12-18, 02:46

Posting Permissions

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