asp.net - 如何使用 ajax 将 id 从客户端传递到 webform
问题描述
我的代码不起作用,我不知道为什么。
我的ajax代码调用:
var id = $(this).attr("data-id")
$.ajax({
type: "POST",
url: "XTM307.aspx/GetPart",
data: { "id": id },
contentType: "application/json",
dataType: "json",
success: function (response) {
}
});
我的服务器代码:
<System.Web.Services.WebMethod()>
<ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json)>
Public Shared Sub GetPart(id As String)
Dim test = 2
test += 3
End Sub
解决方案
您的网络服务方法是GET
,所以 ajax 调用应该是这样的:
var id = $(this).attr("data-id")
$.ajax({
type: "GET",
url: "XTM307.aspx/GetPart?id=" + id,
contentType: "application/json",
dataType: "json",
success: function (response) {
}
});
推荐阅读
- vue.js - 蚂蚁设计上传无法上传大文件
- html - 为输入添加标签
- android - Android 应用的 Firebase Cloud Functions 身份验证
- c++ - 如何找到 std::unordered_map 的当前容量?
- java - 在Java中,在持久化之前解析嵌套对象时获得concurrentModification
- azure - 无法使用数据工厂将多个 BLOB 归档到 Synapse
- mysql - GROUP BY 的 MySQL 键
- javascript - 如何用 puppeteer 抓取 src 图像?
- android - 在 Unity 3d Android 平台中将图像从一个文件夹复制到另一个文件夹
- security - 我可以使用密钥本身计算 RSA 密钥的数据完整性检查吗?