Jquery ajax update issue with chrome

Jquery ajax update issue with chrome

本文关键字:with chrome issue update ajax Jquery      更新时间:2023-09-26

我有这段代码

<div id="status">content here</div>
 <input name="order_data" type="button"  value="<?php echo $order;?>"  class="besttocart"  onclick="gotocart(this);" />

和Javascript

function gotocart(e)
{       
   var origtext = $('#status').html();
    if(getCookie('language').toLowerCase() == 'en'){
   $('#status').html('Loading');
    }else{
    $('#status').html('het laden');        
    }
   $.ajax({           
            url: 'index.php?route=foo/bar',
            type: 'post',
            async:false, /*I strongly suspect something here*/
            dataType:"json",
            success:function(data){
               //do stuff
            }
    });

}

问题出在谷歌浏览器中$('#status').html()当我查看控制台时,它正在更改为"加载"或"het laden"。但它没有显示在我的页面中,我的状态内容仍然是"此处的内容"。在火狐中工作正常

我想

问题出在以下行上:

getCookie('language'),

因为当我像这样更改代码时,

   var origtext = $('#status').html();
    var str=getCookie('language');
   //changed the code here
    if(str && str!='' && str.toLowerCase() == 'en'){
   $('#status').html('Loading');
    }else{
    $('#status').html('het laden');        
    }

这工作正常。

如果未设置 cookie,函数 getCookie 将返回空白,但 toLowerCase 不会在 Chrome 中解析它。因此错误。

你试过使用

document.getElemetnById("status").innerHTML="SOMETHING";