Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

responseText is empty, but shows on console?

This is probably a stupid error, but I'm using JQuery ajax against PHP backend, and I would like the PHP script to post progress back to the webpage.

It looks to be working fine, but I can't get the contents of e.target.responseText.

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

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

Have 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 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
like image 572
johnohod Avatar asked Nov 11 '16 13:11

johnohod


People also ask

What is the difference between response and responseText?

The response is interpreted into a ArrayBuffer , Blob , Document , JavaScript object, or a DOMString , depending on the value of XMLHttpRequest. responseType . responseText , on the other hand is the raw text, and you can handle it however you want. They are very similar in usage though.

What does responseText return?

The read-only XMLHttpRequest property responseText returns the text received from a server following a request being sent.

What is this responseText in Ajax?

The responseText method is used for all formats that are not based on XML. It returns an exact representation of the response as a string. Plain text, (X)HTML, and JSON are all formats that use responseText.


1 Answers

progress is only triggered during the XMLHTTPRequest, not at the end when the response was received

readyState 3: "Downloading; responseText holds partial data."
like image 136
Rajesh Grandhi Avatar answered Oct 06 '22 23:10

Rajesh Grandhi