【问题标题】:Strange behavior in jQuery error responseText from WCF service来自 WCF 服务的 jQuery 错误 responseText 中的奇怪行为
【发布时间】:2012-08-25 15:00:31
【问题描述】:

我有一个在 IIS 中运行的 WCF 服务,方法如下:

public void Test()
{
    HttpContext.Current.Response.StatusCode = 500;
    HttpContext.Current.Response.Write("You cannot do this.");
}

在我的客户端 HTML 页面上,我有以下内容:

$(document).ready(function () {
        $.ajax({
            type: "POST",
            url: 'MyService.svc/Test',
            data: '',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                alert('success');
            },
            error: function (result) {
                alert(result.responseText);
            }
        });
});

错误回调被调用,但 responseText 总是只有两个字符:“Yo”。我检查了响应,它似乎只返回了 2 的内容长度。这是怎么回事?为什么我没有收到回复的全部内容?

【问题讨论】:

    标签: jquery asp.net wcf


    【解决方案1】:

    当您引发异常时,您的消息是否会截断?

    public void Test()
    {
        HttpContext.Current.Response.StatusCode = 500;
        throw new Exception("This is a test");
    }
    

    【讨论】:

      猜你喜欢
      • 2021-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 2015-12-19
      • 2023-03-12
      • 1970-01-01
      相关资源
      最近更新 更多