Unable To Get Ajax's Post Values (plain Javascript)
I'm aware that this question was answered in this forum (Unable to get values in POST php web serivce), but both the question and the answer used jQuery and, in my case, I can't us
Solution 1:
I changed your javascript, and tested this, please try if it work with you :
functioncreate_XHR(){
varXHR = null;
if (window.XMLHttpRequest){
XHR = newXMLHttpRequest();
}
elseif(window.ActiveXObject){
try {
XHR = newActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
XHR = newActiveXObject("Microsoft.XMLHTTP");
}
}
else {
alert("Your navigator is old to run objets XMLHTTPRequest...");
XHR = false;
}
returnXHR;
}
functionajax_post(page, data) {
varXHR = create_XHR();
XHR.open("POST", page, true);
XHR.onreadystatechange = function() {
if (XHR.readyState === 4 && (XHR.status === 200 || XHR.status === 0)) {
console.log("Success Transaction");
}
};
XHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
XHR.send(data);
}
//Running the code ://==================var dataURL = me.video.getScreenCanvas().toDataURL();
ajax_post("http://www.mywebpage.com/image_upload.php", {"imgdata":dataURL});
Modify the cors http : in the server PHP add this in first of your page "image_upload.php":
//Part added by ilyas :if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
//End of part.
Post a Comment for "Unable To Get Ajax's Post Values (plain Javascript)"