Solved

Ajax post- Cross domain request XDR

Posted on 2014-01-10
2
438 Views
Last Modified: 2014-02-04
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'); 
    } 
}

Open in new window


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

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

Open in new window


I get the output as 'NO POST DATA'. Could anyone help me in finding what is wrong here? Many thanks.
0
Comment
Question by:drl1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 500 total points
ID: 39771337
1. Make sure you're following all the rules here:
http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx

2. $HTTP_RAW_POST_DATA is not enabled / available by default. You need to have always_populate_raw_post_data enabled in your php.ini file:
http://www.php.net/manual/en/ini.core.php#ini.always-populate-raw-post-data
(and most setups need to restart PHP/Apache for php.ini changes to take effect)

Alternatively, you can use the php://input stream, which will give you the same data without incurring the performance cost of forcing PHP to always make that raw data available, even if you don't need to use it on other pages.

Courtesy of Ray Paseur's comment on php.net:
<?php $postdata = file_get_contents("php://input"); ?>

Open in new window


That said, the $_POST array is probably what you're looking for, not the raw POST data. For example:

if(isset($_POST["myval"]))
{
  echo $_POST["myval"]; // Should display abc
}

Open in new window


Now, if the intention is to post with the multipart/form-data encoding (usually when you need to also upload files), then the raw data won't even be available. You'll NEED to look at the $_POST array to get that data.
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39771362
By the way, there's a PHP-specific forum area here that would better answer these types of questions in the future.
0

Featured Post

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question