跨域解决 Access to XMLHttpRequest at

html页面
添加这一行 contentType: “application/x-www-form-urlencoded”,

<!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/[email protected]/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");
?>

你可能感兴趣的:(php,python,ajax,vue,json,jquery)