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

时间:2022-10-07 16:50:24

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.

我试图从ASP.NET Gridview行发送一个AJAX请求。 gridview中的每一行都显示已完成的作业。某些作业包含可以下载的文件。这里的最终目标是在彩盒叠加层中显示下载URL,但我现在无法将文件列表返回到基页。要显示要从订单下载文件,我取消隐藏订单号列中的按钮控件。页面上的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.

不知道这里发生了什么。

3 个解决方案

#1


1  

Try sending orderID as a number since you webmethod expects an int, also in JSON keys and strings are quoted with double quotes(")

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

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

#2


1  

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

您在contentType选项中输入了一个拼写错误。应该是:contentType:“application / json; charset = utf-8”

#3


0  

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.

我会回答我的问题,因为任何其他VB.NET/ASP.NET人都遇到了这个问题。除了我的拼写错误之外,这里的问题是我的WebMethod功能是ByRef。它需要是BYVAL。在将我的头撞到墙上并阅读javascript和json服务的一些很棒的东西后,我在http://projectsmm.com/technet/asp/index.shtml找到了真正的答案。 VB.Net默认将函数变量设置为ByRef。出于某种原因,.NET Web服务不接受这一点。改为ByVal,它的工作原理。

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

希望这有助于其他人不花时间我看这个。

#1


1  

Try sending orderID as a number since you webmethod expects an int, also in JSON keys and strings are quoted with double quotes(")

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

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

#2


1  

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

您在contentType选项中输入了一个拼写错误。应该是:contentType:“application / json; charset = utf-8”

#3


0  

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.

我会回答我的问题,因为任何其他VB.NET/ASP.NET人都遇到了这个问题。除了我的拼写错误之外,这里的问题是我的WebMethod功能是ByRef。它需要是BYVAL。在将我的头撞到墙上并阅读javascript和json服务的一些很棒的东西后,我在http://projectsmm.com/technet/asp/index.shtml找到了真正的答案。 VB.Net默认将函数变量设置为ByRef。出于某种原因,.NET Web服务不接受这一点。改为ByVal,它的工作原理。

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

希望这有助于其他人不花时间我看这个。