zoukankan      html  css  js  c++  java
  • js 跨域请求失败

    注:错误返回:Failed to load http://xxxxxxxxxxx: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://m.cd.com' is therefore not allowed access

      如:

    $.post("http://",data,function(result){
    	console.log(result);
                   alert(result);
    	if(result == 'true'){
    		alert('预约成功');
    	}else if(result == 'false'){
    		alert('预约失败');
    	}else{
    		alert(result)
    	}
    },'json')
    

     解决方法:

      

    1.如果请求的是的url是PHP的,须要PHP中文件前头加入 

    echo header("Access-Control-Allow-Origin:*");
    

      

    2.如果请求的html的,这需要加入 

    <meta http-equiv="Access-Control-Allow-Origin" content="*">
  • 相关阅读:
    sklearn
    Scrapy
    正则表达式re
    BeautifulSoup
    requests
    Python网络爬虫与信息提取
    Matplotlib
    Pandas
    NumPy
    制约大数据处理能力的几个问题
  • 原文地址:https://www.cnblogs.com/bubaya/p/7803915.html
Copyright © 2011-2022 走看看