日期:2014-05-16 浏览次数:20726 次
http://localhost/html/1/ajaxj_query.php?q=[{%22name%22:%22zhang%22,%22age%22:36},{%22name%22:%22li%22,%22age%22:24},{%22name%22:%22wang%22,%22age%22:18}]
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">
function onajax() {
var json = [ {
"name" : "zhang",
"age" : 36
}, {
"name" : "li",
"age" : 24
}, {
"name" : "wang",
"age" : 18
} ];
var $a = JSON.stringify(json);
//$a = "[{"name":"zhang","age":36},{"name":"li","age":24},{"name":"wang","age":18}]";
findX($a);
}
function findX(finder) {
var xmlHttp;
if (window.XMLHttpRequest)
xmlHttp = new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari
else
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); // code for IE6, IE5
if (xmlHttp == null) {
alert("Browser does not support HTTP Request");
return;
}
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
//var str = trim(xmlHttp.responseText);
var str = xmlHttp.responseText;
if (str == "") {
alert("好像有问题,什么都没查到!");
return;
}
//对str进行处理
applyQueryX(str);
}
}
var url = "ajaxj_query.php?q=" + finder + "&sid=" + Math.random();
xmlHttp.open("GET", url, true);
xmlHttp.send();
}
function applyQueryX(str) {
alert(str);
}
onajax();
</script>
</body>
</html>
<?php
header("Content-Type:text/html;charset=