【问题标题】:Using Webservice to call external Json file using ajax call使用 Webservice 使用 ajax 调用来调用外部 Json 文件
【发布时间】:2017-11-01 13:39:46
【问题描述】:

我在 Javascript 文件中有一个 Json 文件和一个 ajax 调用。尝试使用 Hello World asmx 文件模板编写正确的 Web 服务方法。我应该在方法中写什么才能使其在网站上显示/返回/读取 json 数据?

$(document).ready(function () {
$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "http://localhost:56537/WebService.asmx/HelloWorld",
    data: "{}",
    dataType: "json",
    success: function (Result) {
        debugger;
        Result = Result.d;
        var data = [];
var dataResource = response 

【问题讨论】:

  • 您仍然可以创建 ASMX Web 服务,但 Microsoft 已经不再支持它了。最好使用 WCF 服务应用程序。您可以使用 DataContractJsonSerilizer。
  • 感谢您的提示!

标签: asp.net json ajax web-services asmx


【解决方案1】:

这就是对我有用的解决方案:

[网络方法]

public string HelloWorld() {

    using (StreamReader r = new StreamReader(@"C:\Users\data.json"))
    {

        string json = r.ReadToEnd();

        return json;

    }

【讨论】:

    猜你喜欢
    • 2012-08-05
    • 1970-01-01
    • 2011-01-05
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多