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 Web ツールでは、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 に答える