Here are two pages, test.php and testserver.php.(这是两个页面,test.php和testserver.php。)
test.php(test.php的)
<script src="scripts/jq.js" type="text/javascript"></script>
<script>
$(function() {
$.ajax({url:"testserver.php",
success:function() {
alert("Success");
},
error:function() {
alert("Error");
},
dataType:"json",
type:"get"
}
)})
</script>
testserver.php(testserver.php)
<?php
$arr = array("element1",
"element2",
array("element31","element32"));
$arr['name'] = "response";
echo json_encode($arr);
?>
Now my problem: when both of these files are on the same server (either localhost or web server), it works and alert("Success")
is called;(现在我的问题是:当这两个文件都在同一台服务器(本地主机或Web服务器)上时,它会工作,并且会调用alert("Success")
;) If it is on different servers, meaning testserver.php on web server and test.php on localhost, its not working, and alert("Error")
is executing.(如果它位于不同的服务器上,意味着Web服务器上的testserver.php和localhost上的test.php,它不起作用,并且正在执行alert("Error")
。) Even if the URL inside ajax is changed to http://domain.com/path/to/file/testserver.php(即使ajax中的URL更改为http://domain.com/path/to/file/testserver.php)
ask by Firose Hussain translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…