responseText
responseXML
onreadyStatechange
响应
0未开始
1建立
2接受
3处理
4完成
request.readyState===4&&request.status===200)
请求
status
var request = new XMLHttpRequest();
request.open("post","service.php");
var data = "name=" + document.getelementbyid("1").value
+"&number=" + document.getelementbyid("2").value
+"&sex=" + document.getelementbyid("3").value
+"&job=" + document.getelementbyid("4").value;
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.send(data)
eval
JASON.parse
var jsondata = '{
}'
var json = eval('('+jsondata+')') 危险,参数直接执行例如alert
var json = JSON.parse(jsondata)
jsonlint校验工具;
<?
header("Content-Type:application/json:charset = utf-8");
?>
//用jQuery实现ajax
$(document).ready(function(){
$("#serch").click(function(){
$.ajax({
type:"get",
url:"sevice.php?number ="$("#keyword").val(),
datatype :"jason",
success:function(data){
if(data.success)注:此处json格式里已经写好了success:ture下同
{$("#result").html(data.msg);}else{
$("#result").html(data.msg);
}
}
});
})
error:function(jqXHR){
alert("jqXHR.status");
}
});
post 需要加data:{}
responseXML
onreadyStatechange
响应
0未开始
1建立
2接受
3处理
4完成
request.readyState===4&&request.status===200)
请求
status
var request = new XMLHttpRequest();
request.open("post","service.php");
var data = "name=" + document.getelementbyid("1").value
+"&number=" + document.getelementbyid("2").value
+"&sex=" + document.getelementbyid("3").value
+"&job=" + document.getelementbyid("4").value;
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.send(data)
eval
JASON.parse
var jsondata = '{
}'
var json = eval('('+jsondata+')') 危险,参数直接执行例如alert
var json = JSON.parse(jsondata)
jsonlint校验工具;
<?
header("Content-Type:application/json:charset = utf-8");
?>
//用jQuery实现ajax
$(document).ready(function(){
$("#serch").click(function(){
$.ajax({
type:"get",
url:"sevice.php?number ="$("#keyword").val(),
datatype :"jason",
success:function(data){
if(data.success)注:此处json格式里已经写好了success:ture下同
{$("#result").html(data.msg);}else{
$("#result").html(data.msg);
}
}
});
})
error:function(jqXHR){
alert("jqXHR.status");
}
});
post 需要加data:{}