core.min.js:36 XMLHttpRequest cannot load http://【地址】. No 'Access-Control-Allow-Origin' header is pr
2015-12-14 19:49
330 查看
core.min.js:36 XMLHttpRequest cannot load http://【地址】. No 'Access-Control-Allow-Origin' header is present
on the requested resource. Origin 'http://192.168.1.222:8080' is therefore not allowed access.
今天一个Ajax跨域问题,纠结我半天
没有结果,chrome用F12 下查看错误 得知:XMLHttpRequest cannot load http://map.oicqzone.com/gpsApi.php?lat=22.502412986242&lng=113.93832783228. Origin http://localhost is not allowed by Access-Control-Allow-Origin. AJAX跨域问题产生。
搜了好久,得知解决方案:
一:使用jsonp格式, 如jquery中ajax请求参数 dataType:'JSONP'。
二,server端加上header设为 Access-Control-Allow-Origin:*
header("Access-Control-Allow-Origin: *"); # 跨域处理
问题就解决了。
on the requested resource. Origin 'http://192.168.1.222:8080' is therefore not allowed access.
今天一个Ajax跨域问题,纠结我半天
<html> <head> <title>title</title> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script> $.ajax({ url:"http://map.oicqzone.com/gpsApi.php?lat=22.502412986242&lng=113.93832783228", type:'GET', success: function(data){ $('body').append( "Name: " + data ); } }); </script> </head> <body> 测试Ajax跨域问题 </body> </html>
没有结果,chrome用F12 下查看错误 得知:XMLHttpRequest cannot load http://map.oicqzone.com/gpsApi.php?lat=22.502412986242&lng=113.93832783228. Origin http://localhost is not allowed by Access-Control-Allow-Origin. AJAX跨域问题产生。
搜了好久,得知解决方案:
一:使用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.oicqzone.com/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: *"); # 跨域处理
问题就解决了。
相关文章推荐
- "http://schemas.xmlsoap.org/wsdl/", the namespace on the "definitions" element, is not a valid SOAP
- 异步的方式查看网络图片
- 计算机网络笔记(二)谢希仁版
- 几种TCP连接中出现RST的情况
- UNIX网络编程卷1 server编程范式0 迭代server
- Apache HTTP Client Removal
- LTE物理层几个基本概念的定义和相互关系 http://blog.sina.com.cn/s/blog_696122b50100n6df.html
- 【负载均衡】四层和七层负载均衡的区别
- 神经网络编程入门
- java发送http的get、post请求
- 实现微信文章页面 http://mp.weixin.qq.com/s?__biz=MjM5MDI3OTAwMg==&mid=200337417&idx=1&sn=5959ed1d722c7da66b
- Alamofire - 优雅的处理 Swift 中的网络操作
- RoboBinding探究三:网络请求实现
- java基础第十二天——网络编程,反射
- 利用urllib2实现http post请求源码示例
- 残差学习,152层网络,微软夺冠2015 ImageNet计算机视觉识别挑战
- C#HTTPPOST请求数据带参数
- tomcat7中启用HTTPS
- 问题解决:Error -27492: "HttpSendRequest" failed, Windows error code=12029
- bzoj-1834 network 网络扩容 【网络流】