简体   繁体   中英

asp.net page not returning ajax request

I am attempting to send an AJAX request from an ASP.NET Gridview row. Each row in the gridview shows completed jobs. Some jobs have files that can be downloaded. The end goal here is to show the download urls in a colorbox overlay, but I am having trouble just returning the list of files to the base page now. To show that there are files to download from an order I unhide a button control in the order number column. Javascript on the page follows.

  $(document).ready(function () {
    $("#<%=gvMessenger.ClientID%> input").filter(":not(:has(table, th))").click(function (e) {

        e.preventDefault();
         var $cell = $(e.target).closest("td");
        //$("#<%=gvMessenger.ClientID%> td").removeClass("highlight"); $cell.addClass("highlight"); $("#message").text('You have selected: ' + $cell.text());
        $("#Message").html("");

        var orderID = $cell.text()
        orderID = $.trim(orderID);
        sendData(orderID);
        function sendData(orderID) {
            var loc = window.location.href;
            loc = (loc.substr(loc.length - 1, 1) == "/") ?
            loc + "CompletedOrdersNew.aspx" : loc;
            $.ajax({
                type: "POST",
                url: loc + "/GetFiles",
                data: "{'orderID':'" + orderID + "'}",
                contentType: "application/jason; charset=utf-8",
                datatype: "json",
                success: function (msg) {
                    $("ContentArea").html(msg.d);
                },
                error: function () {
                    alert("An error occured in getting your files.");
                }
            });
        }
    });
}); 

The function in the page codebehind that should fire on the ajax request follows.

    <WebMethod()> _
Public Shared Function GetFiles(ByRef orderID As Integer) As String
    Dim dict As New Dictionary(Of String, Object)
    Dim dt As DataTable
    dt = Dac.ExecuteDataTable("GetS3Files", Parameter("@OrderID", orderID))
    Dim arrr(dt.Rows.Count) As Object

    For i As Integer = 0 To dt.Rows.Count - 1
        arrr(i) = dt.Rows(i).ItemArray
    Next

    Dim json As New JavaScriptSerializer
    Return json.Serialize(dict)

End Function

When watching the page in FireBug I see the request go out to the GetFiles function with the orderID number {'orderID':'10000315'}

POST http://localhost:57210/AMSSite/Customer/CompletedOrdersNew.aspx/GetFiles

But the call does not fire the GetFiles function and the response I am getting is the page html.

Not sure what is going on here.

尝试将orderID作为数字发送,因为webmethod需要一个int,同样在JSON键和字符串中引用双引号( "

data: "{\"orderID\":" + orderID + "}",

You made a typo in contentType option. Should be: contentType: "application/json; charset=utf-8"

I'll answer my question for the sake of any other VB.NET/ASP.NET folks running into this problem. Aside from my misspelling the issue here was that my WebMethod function was ByRef. It needs to be BYVAL . After banging my head against the wall and reading some great stuff on javascript and json services I found the real answer at http://projectsmm.com/technet/asp/index.shtml . VB.Net by default sets function variables to ByRef. For some reason .NET web services don't accept this. Change to ByVal and it works.

Hope this helps some one else not spend the hours I looked at this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM