【问题标题】:Facing error in ajaxajax面临错误
【发布时间】:2014-01-05 02:08:41
【问题描述】:

我收到错误消息 [object Object] - 错误 - 使用 ajax 调用 asp.net web 方法时发生内部服务器错误。我想使用 ajax 从服务器获取对象列表。

ajax 代码

var Packages;
$.ajax({
type: "POST",
async: false,
url: "http://localhost:54954/WebSite/B/Setting/Packages.asmx/GetAllPackage",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
Packages = response.d;
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.toString() + ' - ' + textStatus + ' - ' + errorThrown);
}
});

网页方法代码

public class Package
{
    public float PackageId;
    public string Code;
    public string Name;
}
[WebMethod]
public List<Package> GetAllPackage() {
    List<Package> PackageList =new List<Package> {};

    for (int i = 1; i <= 100; i++)
    {
        var temp = new Package();
        temp.PackageId = i;
        temp.Code = "Code " +  i;
        temp.Name = "Name" + i;
        PackageList.Add(temp);
    }

        return PackageList;
}

我可以知道我在哪个部分犯了错误吗??

【问题讨论】:

    标签: asp.net ajax asp.net-ajax


    【解决方案1】:

    几个地方.. 对于初学者,您的 WebMethod 不返回 JSON

    我建议阅读以下内容:-What are some simple and fast ways to retieve session variables using javascript or jquery?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-07
      • 2020-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      • 2023-03-23
      • 1970-01-01
      相关资源
      最近更新 更多