我遇到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,48\u043b\u0432."}
這一切都適用於Chrome,FF等罰款,但在IE瀏覽器失敗。
其實IE不會觸發「成功」事件。
我可以得到響應的唯一方法是通過錯誤處理程序。
然後JSON對象具有狀態= 200和狀態文本= OK
這在鉻燒製成功事件後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重寫,相對路徑指向一個不存在的位置。切換到絕對url解決了問題。 – nnikolov06
很高興我可以幫忙;) – VDP