html页面:添加这一行 contentType: “application/x-www-form-urlencoded”html页面:添加这一行 contentType: application/x-www-form-urlencoded !DOCTYPE htmlhtml lang="en"head meta charset="UTF-8" meta name="viewport" content="width=device-width, initial-scale=1.0" title显示小区信息/title script src="https://cdn.staticfile.org/jquery/1.10.2/jq
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>显示小区信息</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
</head>
<body>
<div id="app">
<input v-model="username" class="money" ></input>
</div>
<script>
const header=new Vue({
el:'#app',
data:{
'username':""
},
created:function(){
var that = this;
$.ajax({
contentType: "application/x-www-form-urlencoded",
url: "http://47.94.33.88/ajax/ajax.php",
type:'POST',
data:{
'usrename':that.username
},
success:function (data) {
var json=JSON.parse(data);
that.username=json;
}
})
}
})
</script>
</body>
</html>
php页面添加这一行:header(‘Access-Control-Allow-Origin: *’);
<?php
header('Access-Control-Allow-Origin: *');
echo json_encode("hello");
?>
沃梦达教程
本文标题为:跨域解决 Access to XMLHttpRequest at
猜你喜欢
- 原始CSS美化select下拉框option示例代码 2022-10-05
- Bootstrap .btn-primary类 1970-01-01
- Bootstrap单选按钮 1970-01-01
- js过滤所有特殊字符的实例代码 2022-10-16
- Bootstrap navbar-fixed-bottom类使用 1970-01-01
- D3.js selectAll()用法 2022-07-13
- Bootstrap创建下拉菜单 1970-01-01
- Bootstrap表格行或单元格 1970-01-01
- D3.js数组API 1970-01-01
- Bootstrap .well类 1970-01-01