core.min.js:36 XMLHttpRequest cannot load http://【地址】. No 'Access-Control-Allow-Origin' header is pr

简介: 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bitree1/article/details/50299663 core.
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bitree1/article/details/50299663

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跨域问题,纠结我半天 
 
 
 
 
  1. <html>  
  2. <head>  
  3.     <title>title</title>  
  4.     <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>  
  5.     <script>  
  6.         $.ajax({  
  7.             url:"http://map.oicqzone.com/gpsApi.php?lat=22.502412986242&lng=113.93832783228",  
  8.             type:'GET',  
  9.             success: function(data){  
  10.                 $('body').append( "Name: " + data );  
  11.             }  
  12.         });  
  13.     </script>  
  14. </head>  
  15. <body>     测试Ajax跨域问题 
  16. </body> 
  17. </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'。
 
 
 
  1. <html> 
  2. <head> 
  3.     <title>title</title> 
  4.     <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> 
  5.     <script> 
  6.         $.ajax({ 
  7.             url:"http://map.oicqzone.com/gpsApi.php?lat=22.502412986242&lng=113.93832783228", 
  8.             type:'GET', 
  9.             dataType:'JSONP', 
  10.             success: function(data){ 
  11.                 $('body').append( "Name: " + data ); 
  12.             } 
  13.         }); 
  14.     </script> 
  15. </head> 
  16. <body> 
  17. 测试Ajax跨域问题 
  18. </body> 
  19. </html> 
二,server端加上header设为 Access-Control-Allow-Origin:*
 
header("Access-Control-Allow-Origin: *"); # 跨域处理
问题就解决了。

目录
相关文章
|
4月前
|
JavaScript
node下的two.js调用one.js出现无法编译问题 Cannot find module ‘c:
node下的two.js调用one.js出现无法编译问题 Cannot find module ‘c:
48 0
|
3月前
|
JavaScript
Node.js【GET/POST请求、http模块、路由、创建客户端、作为中间层、文件系统模块】(二)-全面详解(学习总结---从入门到深化)
Node.js【GET/POST请求、http模块、路由、创建客户端、作为中间层、文件系统模块】(二)-全面详解(学习总结---从入门到深化)
30 0
|
4月前
|
JavaScript
Node.js【GET/POST请求、http模块、路由、创建客户端、作为中间层、文件系统模块】(二)-全面详解(学习总结---从入门到深化)(上)
Node.js【GET/POST请求、http模块、路由、创建客户端、作为中间层、文件系统模块】(二)-全面详解(学习总结---从入门到深化)
29 0
|
3月前
|
机器学习/深度学习 前端开发 JavaScript
源映射错误:Error: request failed with status 404 源 URL:http://localhost:8080/bootstrap/js/axios-0.18.0.js
源映射错误:Error: request failed with status 404 源 URL:http://localhost:8080/bootstrap/js/axios-0.18.0.js
50 0
源映射错误:Error: request failed with status 404 源 URL:http://localhost:8080/bootstrap/js/axios-0.18.0.js
|
4月前
|
JavaScript
Node.js【GET/POST请求、http模块、路由、创建客户端、作为中间层、文件系统模块】(二)-全面详解(学习总结---从入门到深化)(下)
Node.js【GET/POST请求、http模块、路由、创建客户端、作为中间层、文件系统模块】(二)-全面详解(学习总结---从入门到深化)
26 0
|
10天前
|
Java Maven
Cannot access repo1 (http://repo1.maven.org/maven2) in offline mode and the
Cannot access repo1 (http://repo1.maven.org/maven2) in offline mode and the
|
11天前
|
JavaScript 前端开发
JavaScript 地址信息与页面跳转
JavaScript 地址信息与页面跳转
|
12天前
|
运维 Serverless API
Serverless 应用引擎产品使用之阿里函数计算中http类型的函数 FC,内网地址如何解决
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。
12 1
|
23天前
|
JavaScript 前端开发
JavaScript 地址信息与页面跳转
JavaScript 地址信息与页面跳转
|
2月前
|
JavaScript
Node.js之http模块
Node.js之http模块