ajax – 406返回JSON对象时出错 – 意外内容
发布时间:2020-12-15 22:55:00 所属栏目:百科 来源:网络整理
导读:一些同事和我有一个问题,即ajax调用的响应返回一些意想不到的内容.而不是使用各种属性获取简单的 JSON对象,result.responseText的值是通用406状态错误页面的HTML标记,表示浏览器不接受MIME类型. 这样的电话是这样的: $.ajax({ url: '/promociones/cincograt
一些同事和我有一个问题,即ajax调用的响应返回一些意想不到的内容.而不是使用各种属性获取简单的
JSON对象,result.responseText的值是通用406状态错误页面的HTML标记,表示浏览器不接受MIME类型.
这样的电话是这样的: $.ajax({ url: '/promociones/cincogratis/canjear-codigo-promocional',type: this.method,data: $(this).serialize(),success: function (result) { $('.promotion_banner .loader').hide(); $('.promotion_banner').html(result); },error: function (result) { var obj = result.responseText; if (obj.isRedirect) { document.location = obj.redirectUrl; } else { $('.promotion_banner .loader').hide(); $(".error-wrapper").removeClass("hidden"); var generic_error = document.getElementById('generic_error').value; $(".error-wrapper p").html(generic_error); } },beforeSend: function() { $('.promotion_banner .loader').show(); } }); 控制器对呼叫的响应如下: Response.StatusCode = (int)HttpStatusCode.NotAcceptable; // 406 return Json(new { errorMessage = LocalErrorMessages.Website_Promotions_FreeFiver_General_Problem,isRedirect = false } ); 我们希望result.responseText包含errorMessage和isRedirect的键值,但它们不在那里. 值得指出的是,这个代码是多租户的,由当前的应用程序和另一个代码共享,它的工作非常好. 我们尝试过: 有没有人遇到过这个问题? 解决方法
简化您的要求.也许是这样的:
$.ajax({ url: '/promociones/cincogratis/canjear-codigo-promocional',type: 'GET',data: {foo:'bar',one:'two'},dataType: 'json',success: function (result) { console.dir(result); },error: function (xhr) { console.dir(xhr) } }); 并从服务器发布响应.这种错误似乎是一个请求问题,而不是服务器配置问题 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |