本文主要是介绍jQuery 跨域访问的三种方式 No 'Access-Control-Allow-Origin' header is present on the reque,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- XMLHttpRequest cannot load http://v.xxx.com. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. test.html:1
- Resource interpreted as Script but transferred with MIME type text/html:
- $(function($){
- var url = 'http://v.juhe.cn/weather/index';
- $.ajax(url, {
- data: {
- 'cityname': '襄阳',
- 'dtype': 'jsonp',
- 'key': 'xxxx',
- '_': new Date().getTime()
- },
- dataType: 'jsonp',
- crossDomain: true,
- success: function(data) {
- if(data && data.resultcode == '200'){
- console.log(data.result.today);
- }
- }
- });
- var url2 = 'http://v.juhe.cn/weather/index?callback=?';
- $.getJSON(url2, {
- 'cityname': '北京',
- 'dtype': 'jsonp',
- 'key': 'xxxx',
- '_': new Date().getTime()
- }, function(data){
- if(data && data.resultcode == '200'){
- console.log(data.result.today);
- }
- });
- var url3 = 'http://v.juhe.cn/weather/index?callback=?';
- $.get(url3, {
- 'cityname': '澳门',
- 'dtype': 'jsonp',
- 'key': 'xxxx',
- '_': new Date().getTime()
- }, function(data){
- if(data && data.resultcode == '200'){
- console.log(data.result.today);
- }
- }, 'json');
- });
这篇关于jQuery 跨域访问的三种方式 No 'Access-Control-Allow-Origin' header is present on the reque的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!