0

我正在使用这段代码:

$("#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 以从后面的代码中获取函数?

4

1 回答 1

1

首先在您的代码隐藏中:

Imports System.Web.Services

然后把它放在你的函数之上,让你的函数公开共享

<WebMethod()> _
Public Shared Function CalcBlockCode() As String
'....
End Function

更新

根据@JsonP 对您的回答的评论,您需要将您的值传递给 ajax 调用,如下所示:

$.ajax({
//...
data: {'paper': $('yourdropdown').val(), 'cylinder':$('yourotherdropdown')} // notice the removal of quotes from around {} as per the comment from @Archer
//...
})
于 2013-11-05T16:25:21.943 回答