简体   繁体   English

asp.net页面没有返回ajax请求

[英]asp.net page not returning ajax request

I am attempting to send an AJAX request from an ASP.NET Gridview row. 我试图从ASP.NET Gridview行发送一个AJAX请求。 Each row in the gridview shows completed jobs. gridview中的每一行都显示已完成的作业。 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. 这里的最终目标是在彩盒覆盖中显示下载URL,但是我现在无法将文件列表返回到基页。 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. 页面上的Javascript如下。

  $(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. 应该触发ajax请求的页面代码隐藏中的函数如下。

    <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'} 在FireBug中观看页面时,我看到请求发送到GetFiles函数,订单号为{'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. 但是调用不会触发GetFiles函数,我得到的响应是页面html。

Not sure what is going on here. 不知道这里发生了什么。

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

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

You made a typo in contentType option. 您在contentType选项中输入了一个拼写错误。 Should be: contentType: "application/json; charset=utf-8" 应该是: 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. 我会回答我的问题,因为任何其他VB.NET/ASP.NET人都遇到了这个问题。 Aside from my misspelling the issue here was that my WebMethod function was ByRef. 除了我的拼写错误之外,这里的问题是我的WebMethod功能是ByRef。 It needs to be BYVAL . 它需要是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 . 在将我的头撞到墙上并阅读javascript和json服务的一些很棒的东西后,我在http://projectsmm.com/technet/asp/index.shtml找到了真正的答案。 VB.Net by default sets function variables to ByRef. VB.Net默认将函数变量设置为ByRef。 For some reason .NET web services don't accept this. 出于某种原因,.NET Web服务不接受这一点。 Change to ByVal and it works. 改为ByVal,它的工作原理。

Hope this helps some one else not spend the hours I looked at this. 希望这有助于其他人不花时间我看这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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