简体   繁体   中英

Ajax post- Cross domain request XDR

This is my JavaScript code to make XDR post request:

if(isIE()) {
    xdr = new XDomainRequest();
    if (xdr) {
        xdr.onerror = err;
        xdr.ontimeout = timeo;
        xdr.onload = loadd;
        xdr.timeout = 10000;
        xdr.open('POST',url);
        xdr.send('myval=abc'); 

    } 
}

And when I try to access the variable myval in PHP:

if(isset($_POST['myval'])) {
    echo 'true';
}
else {
    echo 'false'
}

I get the output as false

Could anyone help me in finding what is wrong here? Many thanks.

Try something like this:

if(isset($HTTP_RAW_POST_DATA)) {
  parse_str($HTTP_RAW_POST_DATA); // here you will get variable $myval
  if($myval== 'abc') {
  echo "TRUE !";
  }
}

You are not sending a key/value pair with XDR. You are sending a string which value is "myval=abc"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM