亲爱的我想知道如何使用 jquery ajax 功能提交 asp.net 表单数据以及我如何在服务器端获取 json 数据
?
最佳答案
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$("#<%=btnSubmit.ClientID %>").click(
function()
{
$.ajax
({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx/AcceptFormData",
data: "{'funcParam':'"+$('#formName').serialize()+"'}",
dataType: "json",
success: function(msg)
{
var msgFromASPXFunction = msg.d
}
});
}
);
});
[System.Web.Services.WebMethod]
public static string AcceptFormData(string funcParam)
{
// this is your server side function
//the data you will get will be in format e.g. a=1&b=2&c=3&d=4&e=5 inside funcParam variable
return "Data Submitted";
}
请注意,服务器端函数名称应与您在 jQuery 的 $.ajax 函数的 url 属性中指定的参数匹配。 (在上面的例子中是“AcceptFormData”
此外,参数名称应与服务器端函数参数的名称相同。在这种情况下,它是“funcParam”。
只需比较此代码中的 $.ajax 和服务器端函数即可。
问候,
阿明赛义德
(注:如有帮助请标示)
关于asp.net - 如何使用 jquery ajax 功能提交 asp.net 表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7608054/