[英]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.