1

我正在尝试使用来自 html 页面的 jQuery 在 aspx 页面中执行 PageMethod,这在我的本地计算机上运行良好。但是,当我将网页部署到远程生产 Web 服务器时,执行 ajax 请求时会收到 401 Unauthorized Error。我的代码如下。

                  $.ajax({
                        type: 'POST',
                        url: 'SupplierMethods.aspx/GetAgeSummaryForPendingDocuments',
                        data: "{ 'supplierId': '" + vid + "'}",
                        dataType: 'json',
                        timeout: 180000, //3 minutes is timeout for this ajax request
                        contentType: "application/json; charset=utf-8",
                        beforeSend: function () {

                        },
                        success: function (json) {
                            stats = json.d.StatsBuckets;
                         },
                        error: function (xhr, textStatus, errorThrown) {
                            alert('An error occurred! ' + (errorThrown ? errorThrown : 
                            xhr.satus));
                        }

                    });
                });   

更新: 我的问题是由于一些非常微不足道的事情。我将网站复制到远程服务器,但忘记复制 dll。PageMethod 在 ASP.Net 网站中被编译成一个 dll,因为它丢失了,所以通过 jQuery ajax 对 PageMethod 的调用返回了一个错误消息。因此,用于 AJAX 的 jQuery API 似乎已经足够好了。

4

1 回答 1

0

我收到此 401 错误是因为 ASP.Net 网站中包含我使用 jQuery ajax 调用的 PageMethod 的新 dll 未部署到远程服务器。所以这个故事的寓意是 - 始终小心部署您的网站,这样您就不会错过任何文件。

还要确保在 jQuery 中调用 ajax 的语法符合语法。

于 2012-11-11T22:25:24.370 回答