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
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.
The read-only XMLHttpRequest property responseText returns the text received from a server following a request being sent.
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.
progress is only triggered during the XMLHTTPRequest, not at the end when the response was received
readyState 3: "Downloading; responseText holds partial data."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With