何为跨域:就是post,get的url不是你自己的网站,域名不同。

解决方案:


方案一:

<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
/*
AJAX跨域问题完美解决方案
研究:袁维
启示:乐锋
*/
function jsonCallBack(url,callback)
{
$.getScript(url,function(){
callback(json);
});
}
function fun1()
{
jsonCallBack('http://b.com/b.php',function(json){
alert(json.message);
})
}
</ script>
<button type="button" onclick="fun1()">跨域访问</button>


—————— http://b.com/b.php ——————-

<?php
$ary
= array('result'=>0,'message'=>'跨域成功');
$json = json_encode($ary);
//一定要这样定义输出最后的JSON数据,这是利用JS的闭包特性
echo "var json=$json;";

?>



方案二:

——————— http://b.com/index ———————-

<script src="jquery-1.4.2.js" type="text/javascript"></script>
<script type="text/javascript">
function fun1()
{
$.getJSON("http://a.com/c.php?no=10&msg=ok&format=json&jsoncallback=?",
function(data){
alert(data.msg);
});
}
</script>
<button type="button" onclick="fun1()">跨域处理</button>


——————– http://a.com/c.php ———————-

<?php
$no
= $_GET['no'];
$msg = $_GET['msg'];
$json = json_encode(array('no'=>$no,'msg'=>$msg));
//必需以下这样输出
echo $_GET['jsoncallback'].'('.$json.')';