[英]Pass Query String Value into jQuery Ajax Call in ASP.NET
我有一个带单个参数的webMethod,我想通过jQuery Ajax调用。 现在,该参数应该是我在其中进行ajax调用的URL的查询字符串。 我不知道如何将查询字符串作为参数从jQuery ajax传递到方法中。 我的代码如下
C#方法
[WebMethod]
public static string FollowUser(string userId)
{
//Code to follow user
//returns a string value
}
jQuery Ajax
$(document).ready(function() {
$("#btnFollow").click(function() {
$.ajax({
type: "POST",
url: "Default.aspx/FollowUser",
data: //how do I pass the query string here
contentType: "application/json; charset=utf-8", datatype: "json",
context: this,
success: function(msg) {
//I'm doing some stuff here
}
},
error: function(response) {
alert(response.d);
}
});
});
});
有人帮我。 谢谢。
您需要将数据作为URL的一部分传递或将方法更改为GET。 提交包含数据的aJax帖子时,您会将数据作为请求正文的一部分发送(表单数据)。 这不是查询字符串属性,而是内容的一部分。 而是更改URL以包括数据。 例。
Default.aspx/FollowUser?userId=user1
更改为GET方法将强制将post参数改为查询字符串的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.