使用Webservice使用ajax调用调用外部Json文件

时间:2017-05-31 16:24:21

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

我在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 

1 个答案:

答案 0 :(得分:0)

这是解决方案对我有用:

[的WebMethod]

public string HelloWorld() {

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

        string json = r.ReadToEnd();

        return json;

    }
相关问题