ajax_php.php
<?php
/**//echo print_r(json_decode($arr));
index.html
<html>
<head>
<title>ajax</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" charset="utf-8" src="jquery-2.1.4.min.js"></script>
<script>
$(function(){
var my_data="前台变量";
my_data=escape(my_data)+"";//编码,防止汉字乱码
$.ajax({
url: "ajax_php.php?id=1",
type: "get",
data:{trans_data:my_data},
dataType: "json",
error: function(){
alert('Error loading XML document');
},
success: function(data,status){//如果调用php成功
alert(unescape(my_data));
alert(data[0]['id']);
}
});
});
</script>
</head>
</html>
注意:jq在官网上下载 后台传入的值要和dataType一致