zoukankan      html  css  js  c++  java
  • 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');
        });
    

      

  • 相关阅读:
    爬取卡通图片
    python 列表生成式
    python 装饰器
    python 协程 and 进程
    ssh登录缓慢问题
    解决 input 元素点击有蓝色边框的问题
    JavaScript面试题总结系列(九)
    JavaScript面试题总结系列(八)
    JavaScript面试题总结系列(七)
    JavaScript面试题总结系列(六)
  • 原文地址:https://www.cnblogs.com/siaslfslovewp/p/5053671.html
Copyright © 2011-2022 走看看