我正在使用这段代码:
$("#dropdownPaper").change(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "NomexLine500A.aspx/CalcBlockCode",
data: "{}",
dataType: "json",
success: function (data) {
$("#textBlockCode").text(data.d)
},
error: function (result) { }
});
});
响应下拉列表更改以在 aspx 页面的代码隐藏文件中运行函数。
这是后面代码中的函数:
Protected Function CalcBlockCode() As String
Dim strReturn As String
Dim paper As New DropDownList
Dim cylinder As New DropDownList
'Dim blockcode As New TextBox
paper = FormView1.FindControl("dropdownPaperItem")
cylinder = FormView1.FindControl("dropdownCylinderNumber")
'blockcode = CType(FormView1.FindControl("textBlockCode"), TextBox)
If paper.Text = "" Or paper.Text = "None" Then
CalcBlockCode = "NA"
Exit Function
End If
If cylinder.Text = "" Or cylinder.Text = "None" Then
CalcBlockCode = "NA"
Exit Function
End If
Dim strCellSizeCode As String
Dim intMil As Decimal
Dim strCylinderID As String
strCellSizeCode = DLookup("CellSizeCode", "Cylinders", "CYLINDERS = '" & cylinder.Text & "'")
intMil = DLookup("Mil", "PaperPart", "ITEM_NBR = '" & paper.Text & "'")
strCylinderID = DLookup("CylinderID", "Cylinders", "CYLINDERS = '" & cylinder.Text & "'")
strReturn = Convert.ToInt32(intMil * 10) & strCellSizeCode & strCylinderID
CalcBlockCode = strReturn
End Function
在 Firefox 网络工具中,我没有看到 jquery 函数正在运行的任何证据。如果它运行,我没有得到返回值。我是否为 ajax 调用引用了正确的 url 以从后面的代码中获取函数?