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")
;)
alert("Error")
is executing. (如果它位于不同的服务器上,意味着Web服务器上的testserver.php和localhost上的test.php,它不起作用,并且正在执行alert("Error")
。)
(即使ajax中的URL更改为http://domain.com/path/to/file/testserver.php)
ask by Firose Hussain translate from so