Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. XMLHttpRequest - limitation receiving data asynchronously
Forum Updated to NodeBB v4.3 + New Features

XMLHttpRequest - limitation receiving data asynchronously

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BjoernK
    wrote on last edited by
    #1

    Hello everybody.

    I'm developing a mobile QtQuick app but I encountered a general problem with the XMLHttpRequest-object:
    The app communicates with a server via a JSON API (sending JSON objects and receiving JSON objects as response).
    I use the XMLHttpRequest for asynchronous requests. There is one API call that makes the server respond with a JSON object which contains about ~500 data records (< 40 kilobytes). I can't manage to receive this response object. I checked that the server sends valid JSON data.
    Do I have to modify the HTTP headers for the app's requests?
    The mentioned response object is received successfully when the app requests the data synchronously.

    I shortened the JavaScript-method which I use to request data. The second parameter of the function is supposed to be a function to allow processing of the received data.

    function test(jsonRequest, callBack)
    {
        var http = new XMLHttpRequest()
        var url = "http://example.com"
        var async = true
        http.open("POST", url, async)
        // send the proper header information along with the request
        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
        http.setRequestHeader("Content-length", jsonRequest.length)
        http.setRequestHeader("Connection", "Close")
        http.onreadystatechange = function()
        {
            if (http.readyState === XMLHttpRequest.DONE)
            {
                if (http.status === 200)
                {
                    var jsonResponse = http.responseText
                    try
                    {
                        if (jsonResponse == "")
                        {
                            throw "API-Error"
                        }
                        var jsonResponseObject = JSON.parse(jsonResponse)
                        if (typeof(callBack) == "function")
                            callBack(jsonResponseObject)
                        else
                            throw "no callBack-function specified: type of callBack: " + typeof(callBack)
                    }
                    catch(e)
                    {
                        if (Qt.platform.os == "windows")
                            console.log("\n\n" + e + ":\njsonRequest: >" + jsonRequest + "<\njsonResponse: >" + jsonResponse + "<\n")
                    }
                }
            }
        }
        http.send(jsonRequest)
    }
    

    Thank you for reading.

    Best regards,
    Björn

    raven-worxR 1 Reply Last reply
    0
    • B BjoernK

      Hello everybody.

      I'm developing a mobile QtQuick app but I encountered a general problem with the XMLHttpRequest-object:
      The app communicates with a server via a JSON API (sending JSON objects and receiving JSON objects as response).
      I use the XMLHttpRequest for asynchronous requests. There is one API call that makes the server respond with a JSON object which contains about ~500 data records (< 40 kilobytes). I can't manage to receive this response object. I checked that the server sends valid JSON data.
      Do I have to modify the HTTP headers for the app's requests?
      The mentioned response object is received successfully when the app requests the data synchronously.

      I shortened the JavaScript-method which I use to request data. The second parameter of the function is supposed to be a function to allow processing of the received data.

      function test(jsonRequest, callBack)
      {
          var http = new XMLHttpRequest()
          var url = "http://example.com"
          var async = true
          http.open("POST", url, async)
          // send the proper header information along with the request
          http.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
          http.setRequestHeader("Content-length", jsonRequest.length)
          http.setRequestHeader("Connection", "Close")
          http.onreadystatechange = function()
          {
              if (http.readyState === XMLHttpRequest.DONE)
              {
                  if (http.status === 200)
                  {
                      var jsonResponse = http.responseText
                      try
                      {
                          if (jsonResponse == "")
                          {
                              throw "API-Error"
                          }
                          var jsonResponseObject = JSON.parse(jsonResponse)
                          if (typeof(callBack) == "function")
                              callBack(jsonResponseObject)
                          else
                              throw "no callBack-function specified: type of callBack: " + typeof(callBack)
                      }
                      catch(e)
                      {
                          if (Qt.platform.os == "windows")
                              console.log("\n\n" + e + ":\njsonRequest: >" + jsonRequest + "<\njsonResponse: >" + jsonResponse + "<\n")
                      }
                  }
              }
          }
          http.send(jsonRequest)
      }
      

      Thank you for reading.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @BjoernK
      such a feature is not part of the HTTP standard.
      Is the server application under your control? If so you need to add a custom parameter to the request to define the response limit.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      B 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @BjoernK
        such a feature is not part of the HTTP standard.
        Is the server application under your control? If so you need to add a custom parameter to the request to define the response limit.

        B Offline
        B Offline
        BjoernK
        wrote on last edited by
        #3

        @raven-worx
        Thank you for your answer.
        The server is not directly under my control but I can send suggestions to the person in charge. I will suggest to modify the API so one can specify the desired amount of data records per call.

        Best regards,
        Björn

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved