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="*">
原文地址:https://www.cnblogs.com/bubaya/p/7803915.html