post就无法实现跨域的意思吗
除了后台的代理,jsonp只能实现get请求的跨域,xhr2不支持10以下,那post请求怎么实现跨域的呢??
除了后台的代理,jsonp只能实现get请求的跨域,xhr2不支持10以下,那post请求怎么实现跨域的呢??
2016-11-27
主要是Access-Control-Allow-Origin头参数,该参数用来指定允许哪个来源的域请求。服务端:
// 表示支持所有来源的域进行请求
// 实际在操作过程中可以设置为指定域
header('Access-Control-Allow-Origin:*');
$data = json_encode(array("id" => "1", "name" => "tom"));
echo $data;js
$.ajax({
type: "POST",
url: "http://127.0.0.1/~chenjiebin/mycode/php/crossdomain/header.php",
dataType: "json",
success: function(data) {
console.log(data);
}
});有没有用不知道~~~
举报