微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 通过ajax获取json数据

希望这是一个相当容易的问题.原谅我的无知,但我主要是一个PHP / Zend开发人员,所以我在C#和Visual Studio中遇到json / ajax问题.有什么明显的东西我不见了吗?任何帮助将不胜感激.我应该看List<>?

这是我在解雇javascript ajax函数时收到的错误
“未知的网络方法getwidgets.”

我在C#中有一个数据集,我通过JSON转换器方法运行.这很好用,并在JSON字符串中返回我的数据.

private widgetsBL widgetsBLObject = new widgetsBL();

[WebMethod]
public String getwidgets()
{
    DataSet results = new DataSet();
    results = widgetsBLObject.selectTheWidgets();

    string jsresults = MyClassLibrary.JqueryTools.GetJSONString(results.Tables[0]);
    return jsresults;
}

这是jsresults:

{"Table" : [  {"widgetid" : "1","widgetname" : "gizmo1000","widgetdescription" : "very cool widget"},
{"widgetid" : "2","widgetname" : "gizmo2000","widgetdescription" : "decent widget"},
{"widgetid" : "3","widgetname" : "gizmo3000","widgetdescription" : "terrible widget"}     ]}

我的Javascript电话:

$.ajax({
    type: "POST",
    url: "my.aspx/getwidgets",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
       // do stuff with returned data
    }
});

解决方法:

getwidgets需要是静态的

[WebMethod]
public static String getwidgets()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐