Is ResponseText empty but showing on console?

This is probably a stupid mistake, but I'm using jQuery ajax for a PHP server, and I would like the PHP script to publish the progress on a web page.

It seems to be working fine, but I cannot get the contents of e.target.responseText.

If I do console.log (e.target), I get the XMLHttpRequest object in the console. And I see responseText: "1 av 1500 linjer"

But if I do console.log (e.target.responseText), it is empty.

Am I lost my mind?

This is my function:

$.ajax(
    {
        type: "POST",
        url: "modEcs/ajax/ecs.php?a=analyseExcel",
        processData: false,
        contentType: false,
        xhrFields: 
        {
        onprogress: function(e) 
        {               
            console.log(e.target);
            console.log(e.target.responseText);  
            }
        },
        success: function(data) 
        {

         },
         error: function (xhr, ajaxOptions, thrownError) { alert(xhr.statusText); }
    });

Data in the console:

XMLHttpRequest
onabort: null
onerror: null
onload: null
onloadend: null
onloadstart: null
onprogress: function(e)
onreadystatechange: null
ontimeout: null
readyState: 4
response: "1 av 1500 linjer"
responseText: "1 av 1500 linjer"
responseType: ""
responseURL: "xxx"
responseXML: null
status: 200
statusText: "OK"
timeout: 0
upload: XMLHttpRequestUpload {onloadstart: null, onprogress: null, onabort: null, onerror: null, onload: null, …}
withCredentials: false
XMLHttpRequest-prototype
+7
source share
3 answers

progress only starts during XMLHTTPRequest and not at the end when the response was received

readyState 3: "Downloading; responseText holds partial data."
+1

,

$.ajax({
     type: "POST",
     url: "modEcs/ajax/ecs.php?a=analyseExcel",
     processData: false,
     contentType: false,
     xhr: function(){
        var xhr = new window.XMLHttpRequest();
        // Handle progress
        xhr.addEventListener("progress", function(evt){
        //Do some progress calculations
          console.log(xhr.responseText);
     }, false);

   return xhr;
  },
  complete:function(){
    console.log("Request finished.");
  }
});
0

, onprogress, . responseText .

, responseText ( .log() onprogress), , success, e. , , , , Live, , , . , , . target.responseText , , .

Hope this helps future readers.

0
source

Source: https://habr.com/ru/post/1660499/


All Articles