错误事件在JSONP中触发

时间:2012-11-13 15:38:01

标签: c# asp.net

此js fire服务器端api调用和C#也成功返回,但它在js中出现错误函数。我无法看到响应错误的结果。

JS

$.ajax({
    url: "http://127.0.0.1:81/api/sites/GetDomainAvailability?apikey=asfasfdsf&callback=?",
    data: { subDomain: subDomain, parentDomain: parentDomain, resellerId: resellerId },
    contentType: 'application/json; charset=utf-8',
    accept: 'application/json',
    dataType: 'json',
    success: function (response) {
        if (callback)
            callback(response.d);
    },
    error: function (response) {
        if (callback)
            error(response.d);
    }
});

C#代码

 [HttpGet]
        public HttpResponseMessage GetDomainAvailability(string subDomain, string parentDomain, string resellerId)
        {
            if (ModelState.IsValid)
            {
                var domain = string.Format("{0}.{1}", subDomain, parentDomain);

                var manager = new CloudSitesManager();
                var isDomainAvailable = manager.GetDomainAvailability(domain);

                var response = Request.CreateResponse(HttpStatusCode.OK, isDomainAvailable);
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }

1 个答案:

答案 0 :(得分:0)

您需要确保在web.config(以及任何WCF声明)中使用includeExceptionDetailInFaults =“True”。在DEBUG模式下编译它以确保您获得最大的异常细节。

编辑:去生产时再把它关掉!!