【问题标题】:Unable to make Ajax Call - ASP.Net无法进行 Ajax 调用 - ASP.Net
【发布时间】:2015-12-18 07:35:47
【问题描述】:

使用 jQuery 1.11.0。
当我进行 Ajax 调用时,错误是

发布http://localhost:9909/Admin/ReportsService.asmx?GetQuestionSets 500(内部服务器错误)

但我可以浏览 URL 并运行该方法而没有任何问题。

reports.js:

function getQuestionSets() {    
    $.ajax({
        type: "POST",
        url: "/Admin/ReportsService.asmx?GetQuestionSets",        
        data: "{ 'startDate': '" + $(".txtFromDate").val() + "', 'endDate': '" + $(".txtToDate").val() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",        
        success: function (msg) {
            console.log(msg.d);
        },
        Error: function (x, e) {
            // On Error
        }
    });
}

ReportsService.asmx:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
[System.Web.Script.Services.ScriptService]
public class ReportsService : WebService 
{
 [WebMethod]
    public void GetQuestionSets(string startDate, string endDate)
    {
      //code to get data.
    }
}

web.config:

<webServices>
        <protocols>
          <add name="HttpGet" />
          <add name="HttpPost" />
        </protocols>
      </webServices>
    </system.web>

方法GetQuestionSets 的断点永远不会被命中。 我在这里错过了什么。

【问题讨论】:

    标签: jquery asp.net ajax web-services


    【解决方案1】:

    问题似乎出在url 你正在调用你的方法,就好像你正在传递一个查询字符串

    变化:

     url: "/Admin/ReportsService.asmx?GetQuestionSets"
    

    到:

     url: "/Admin/ReportsService.asmx/GetQuestionSets"
    

    【讨论】:

    • 更改后问题仍然存在
    • @Qwerty - 确保你点击了相对于你的 JS 的正确 url。我试过你的代码,它对我来说工作正常。
    【解决方案2】:

    请检查发布到端点的数据是否格式正确。您提到:“我能够毫无问题地浏览 URL 并运行该方法”——是实际数据记录到浏览器控制台,还是手动添加日期?查看实际记录的数据(或者您通过Fiddler 拨打电话时看到的内容)是否会导致问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-10
      • 2013-08-25
      • 1970-01-01
      • 1970-01-01
      • 2014-08-16
      • 1970-01-01
      • 2020-01-25
      • 1970-01-01
      相关资源
      最近更新 更多