简体   繁体   English

跨域连接不起作用

[英]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: 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(第二域):

<?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 . 在$ .ajax选项中, method属性实际上应命名为type

Check out this link for more details -> http://api.jquery.com/jQuery.ajax/ 查看此链接以获取更多详细信息-> http://api.jquery.com/jQuery.ajax/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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