php – jQuery $.ajax请求在Internet Explorer中收到错误的响应
发布时间:2020-12-13 17:13:13 所属栏目:PHP教程 来源:网络整理
导读:我遇到了ajax json请求和Internet Explorer的问题. 具体来说,ajax请求行为不正常. 我正在使用: OpenCart 1.5.3.1 jQuery的1.7.1.min.js jQuery的UI,1.8.16.custom.min.js Internet Explorer 9 PHP 5.2.9 这是请求函数: function addToCart(product_id,quan
我遇到了ajax json请求和Internet Explorer的问题.
具体来说,ajax请求行为不正常. 我正在使用: OpenCart 1.5.3.1 jQuery的1.7.1.min.js jQuery的UI,1.8.16.custom.min.js Internet Explorer 9 PHP 5.2.9 这是请求函数: function addToCart(product_id,quantity,option_id,option_value) { quantity = typeof(quantity) != 'undefined' ? quantity : 1; option_value = typeof(option_value) != 'undefined' ? option_value : 0; option_id = typeof(option_id) != 'undefined' ? option_id : 0; jQuery.ajax({ url: 'index.php?route=checkout/cart/add',type: 'post',cache: false,data: 'product_id=' + product_id + '&quantity=' + quantity + '&option_id=' + option_id + '&option_value=' + option_value+'&rnd=' + Math.random(),dataType: 'json',success: function(jsonObj) { $('.success,.warning,.attention,.information,.error').remove(); if (jsonObj['redirect']) { location = jsonObj['redirect']; } if (jsonObj['success']) { $('#notification').html('<div class="success" style="display: none;">' + jsonObj['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.success').fadeIn('slow'); $('#cart-total').html(jsonObj['total']); $('html,body').animate({ scrollTop: 0 },'slow'); } } }); } PHP函数返回: {"success":"Added to cart!","total":"1 product(s) - 52,48u043bu0432."} 这一切都适用于Chrome,FF等,但在IE中失败. 实际上IE并没有触发“成功”事件. 这是在Chrome中触发成功事件后的json对象: jsonObj: Object success: "Added to cart!" total: "1 product(s) - 52.48лв." __proto__: Object 从中使用“成功”和“总计”值. 这是在Internet Explorer中处理错误事件后的json对象: responseText是一个包含当前页面html源的字符串. 我试过jQuery.ajaxSetup({cache:false});但结果是一样的. 有人有这个问题吗?或任何提示? 解决方法
尝试使用绝对网址为url:’index.php?route = checkout / cart / add’
问题是您的响应是html或xml(我看到xml页面的开始标记(命名空间标记),后跟换行符后跟(旧)html起始标记). jQuery期待json.所以这是一个解析错误,导致在预期成功的标准中出现错误回调. 确保后端发送正确的信息并且被叫页面是正确的.您可以使用网络选项卡捕获调用以查找问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读