Resolves Ajax cross-domain issues: Origin xx is not allowed by Access-control-allow-origin.
Today an AJAX cross-domain problem, tangled in my half-day, record it.
<HTML><Head> <title>Title</title> <Scriptsrc= "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', Success:function(data) {$ ('Body'). Append ("Name:" +data); } }); </Script></Head><Body>Testing Ajax cross-domain issues</Body></HTML>
No results, chrome with F12 to see the error: XMLHttpRequest Cannot load http://map.yanue.net/gpsApi.php?lat=22.502412986242&lng= 113.93832783228. Origin http://localhost is not allowed by Access-control-allow-origin. Ajax cross-domain issues arise.
Search for a long time, know the solution:
One: Use the JSONP format, such as jquery in the ajax request parameter DataType: ' JSONP '. (optional)
<HTML><Head> <title>Title</title> <Scriptsrc= "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>Testing Ajax cross-domain issues</Body></HTML>
Second, server side plus header set to access-control-allow-origin:*
// cross-domain processing
The problem is solved.
Thank you: http://yanue.net/post-130.html
Resolves Ajax cross-domain issues: Origin xx is not allowed by Access-control-allow-origin.