解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin.
生活随笔
收集整理的這篇文章主要介紹了
解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin.
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一:使用jsonp格式, 如jquery中ajax請求參數 dataType:'JSONP'。
<html>
<head>
<title>title</title>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$.ajax({
url:"http://map.yanue.net/gpsApi.php?lat=22.502412986242&lng=113.93832783228",
type:'GET',
dataType:'JSONP',
success: function(data){
$('body').append( "Name: " + data );
}
});
</script>
</head>
<body>
測試Ajax跨域問題
</body>
</html>
二,server端加上header設為 Access-Control-Allow-Origin:*
header("Access-Control-Allow-Origin: *"); # 跨域處理
header(“Access-Control-Allow-Methods”, “POST,OPTIONS,GET”);
總結
以上是生活随笔為你收集整理的解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin.的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 浅谈医院预防电气火灾的措施
- 下一篇: 如何正确安装隔爆型阀门电动装置?不妨来看