我要跨域获得服务端json数据,但服务端代码不可变。
服务端代码:
<?php
header('Content-Type:text/html;Charset=utf-8');
$arr = array(
"user" => $_GET['loginuser'],
"pass" => $_GET['loginpass'],
"name" => 'response'
);
echo json_encode($arr);
?>
客户端代码:
var script = document.createElement("script");
script.src = "https://www.xxx.com/TEST.php?loginuser=lee&loginpass=123456";
document.body.appendChild(script);
这时chrome network打印出了json数据,但是怎么获取这些json数据呢?注意:不允许在php中拼回调函数!
想要跨域获取数据,又不修改服务器的话,不可行。
否则,就可以跨域取任何网站的资源了。