Skip to content Skip to sidebar Skip to footer

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.

Solution 2:

I think that you need to configure you server apache in file httpd.conf

Under Apache, the limit is a configurable value, LimitRequestLine. Change this value to something larger than its default of 8190 if you want to support a longer request URI.

change :

LimitRequestLine4094

to a value < 8190

Post a Comment for "Unable To Get Ajax's Post Values (plain Javascript)"