post 接收为text
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<input id="username" name="username" type="text">
<input type="button" value="点击" onclick="ajaxInvoke()">
</body>
<script>
function ajaxInvoke() {
var uname=$("#username").val();
var opt={
type:"post",
url:"",
data:{
username:uname,
},
dataType:"text",
success:function (responseText) {
var jasonObj = $.parseJSON(responseText)
},
error:function () {
}
};
$.ajax(opt);
}
</script>
</html>
post 接收数据为json
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<input id="username" name="username" type="text">
<input type="button" value="点击" onclick="ajaxInvoke()">
</body>
<script>
function ajaxInvoke() {
var uname=$("#username").val();
var opt={
type:"post",
url:"",
data:{
username:uname,
},
dataType:"json",
success:function (responseJSON) {
var a=responseJSON.a;
var b=responseJSON.b;
var c=responseJSON.c;
for(var i=0;i<responseJSON.length;i++){
a[i]=responseJSON[i].a;
b[i]=responseJSON[i].b;
c[i]=responseJSON[i].c;
}
},
error:function () {
}
};
$.ajax(opt);
}
</script>
</html>