如何在.net中模拟post方式提交json数据
1个回答
展开全部
以下是我在项目中的一个例子,Jquery 调用WebService,用POST方法,类型是Json格式:
$.ajax({
type: "POST",
url: "WebServiceInfos.asmx/SetStudentInfo",
data: "{name:'" + stuName + "',sex:'" + stuSex + "',age:'" + stuAge + "',sid:'" + stuSid + "'}",
contentType: "Application/Json",
dataType:'Json',
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept","Application/Json");
},
success: function (data) {
$("#alterDiv").html("");
$("#alterDiv").append("年龄:"+data.d.StuAge + "姓名:"+data.d.StuName + "学号:" + data.d.StuSid + "性别:" + data.d.StuSex);
},
complete: function (XMLHttpRequest, textStatus) {
var returnText = XMLHttpRequest.responseText;
$("#backData").html(returnText); // 输出服务器端返回数据
}
})
$.ajax({
type: "POST",
url: "WebServiceInfos.asmx/SetStudentInfo",
data: "{name:'" + stuName + "',sex:'" + stuSex + "',age:'" + stuAge + "',sid:'" + stuSid + "'}",
contentType: "Application/Json",
dataType:'Json',
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept","Application/Json");
},
success: function (data) {
$("#alterDiv").html("");
$("#alterDiv").append("年龄:"+data.d.StuAge + "姓名:"+data.d.StuName + "学号:" + data.d.StuSid + "性别:" + data.d.StuSex);
},
complete: function (XMLHttpRequest, textStatus) {
var returnText = XMLHttpRequest.responseText;
$("#backData").html(returnText); // 输出服务器端返回数据
}
})
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询