I need to send data to another domain. Now I use jquery and ajax
var post_data = {
foo: "foo",
bar: "bar"
};
jQuery.ajax({
url:"https://notmydomain.com/polling/?d=jsonp",
crossDomain:true,
dataType:"jsonp",
cache:false,
data: post_data,
type: "post"
});
It works fine, but I need to send it using php. Try to use this solution:
$post_data = http_build_query(
array(
'foo' => 'foo',
'bar' => 'bar'
)
);
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $post_data
)
);
$context = stream_context_create($opts);
$result = file_get_contents('https://notmydomain.com/polling/?d=jsonp', false, $context);
But it's not work. I'm think cause of specific options in ajax like:
crossDomain:true,
dataType:"jsonp",
cache:false
Don't know how to solve it, need help!