本机上的ajax需要跨域吗,jQuery AJAX跨域
生活随笔
收集整理的這篇文章主要介紹了
本机上的ajax需要跨域吗,jQuery AJAX跨域
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
jQuery AJAX跨域
這是兩個頁面,test.php和testserver.php。
test.php的
$(function()?{
$.ajax({url:"testserver.php",
success:function()?{
alert("Success");
},
error:function()?{
alert("Error");
},
dataType:"json",
type:"get"
}
)})
testserver.php<?php
$arr?=?array("element1",
"element2",
array("element31","element32"));$arr['name']?=?"response";echo?json_encode($arr);?>
現在我的問題是:當這兩個文件都在同一臺服務器(localhost或web服務器)上時,它可以工作并被alert("Success")調用;?如果它位于不同的服務器上,意味著Web服務器上的testserver.php和localhost上的test.php,它就無法工作,并且alert("Error")正在執行。即使ajax中的URL更改為http://domain.com/path/to/file/testserver.php
總結
以上是生活随笔為你收集整理的本机上的ajax需要跨域吗,jQuery AJAX跨域的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux常用架构,Linux常用到的一
- 下一篇: android 文本倒影,android