最基本用法
$.ajax({
type: "GET",
url: "regcheck.php?type=code&v=" + code,
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(json) {
if (json.type == 1) {
if(json.status == 1){
$("#validCode").html("ok");
}
else{
$("#validCode").html("wrong");
}
} else {
$("#validCode").html("false");
}
},
error: function (msg) {
alert(msg);
}
});
}
简单用法($.post)
<pre name="code" class="javascript">$.get("regcheck.php?type=code&v=" + code, function(json) {
if (json.type == 1) {
if(json.status == 1){
$("#validCode").html("ok");
}
else{
$("#validCode").html("wrong");
}
} else {
$("#validCode").html("false");
}
},"json");
专门json用法
<pre name="code" class="javascript"> $.getJSON("regcheck.php?type=userName&v=" + userName, function(json) {
if (json.type == 1) {
if(json.status == 0){
$("#validUserName").html("OK");
}
else{
$("#validUserName").html("用户名已存在");
}
} else {
$("#validUserName").html("数据有误");
}
});