Returning Value To Javascript From Php Called From Xmlhttprequest
I am attempting to add an 'Upload Image' feature to my AjaxChat window. The upload to the server works great, but now I need to be able to return the tmp_name/location of the file
Solution 1:
When you use XMLHttpRequest
, the output of the server script is in the responseText
of the object. So you can do:
xhr.onload = function () {
if (xhr.status === 200) {
//File(s) uploaded
uploadButton.innerHTML = xhr.responseText;
} else {
alert('An error occurred!');
}
};
If you want to send back multiple pieces of information, such as an informative message and the name of the file, you can use JSON to encode an associative array, which will become a Javascript object when you parse it.
Post a Comment for "Returning Value To Javascript From Php Called From Xmlhttprequest"