1.跨域请求Access to XMLHttpRequest at 'http://localhost:8080/api/user/login' from origin 'http://localhost
在被请求的php文件中加入请求头部
header('Access-Control-Allow-Origin: *');
*.php
<?php
header('Access-Control-Allow-Origin: *');
$arr = [
array('id'=>1,'title'=>'one1'),
array('id'=>2,'title'=>'one2'),
array('id'=>3,'title'=>'one3'),
array('id'=>4,'title'=>'one4'),
];
echo json_encode($arr);
?>
index.html
<script type="text/javascript" src="jq.js"></script>
<script type="text/javascript">
$.ajax({
type:'post',
url: 'http://127.0.0.1/demo1/api.php',
contentType: "application/x-www-form-urlencoded",
dataType: 'json',
success: function(res){
console.log(res)
}
})
</script>