简体   繁体   中英

cross-domain connection not working

I have to communicate between two servers. I read a tutorial. It is working fine in demo. But when i use it for me, it is not working.

jQuery:

$.ajax({
url : "http://www.foobar.bar.com/update.php",
data: "name=WE HEART IT",
method : "POST",
crossDomain:true,
cache:false,
success: function(data){
   alert(data);
} 
});

PHP (2nd Domain) :

<?php

header('Access-Control-Allow-Origin: *');

if (version_compare(phpversion(), '5.3.0', '>=')  == 1)
  error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
else
  error_reporting(E_ALL & ~E_NOTICE);

echo $_POST['name'];

?>

In your options for $.ajax, the method property should actually be named type .

Check out this link for more details -> http://api.jquery.com/jQuery.ajax/

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