无法在ajax调用中加载内容

时间:2016-05-23 15:30:34

标签: javascript php html ajax

我在网页上有一个带有此代码的功能:

enter code here function LoadGrid() { 
  var gridder = $('#as_gridder'); 
  var UrlToPass = "action=load"; 
  //was var UrlToPass = 'action=load'; 
  gridder.html('loading..');       
  $.ajax({ 
     url : 'cartajax.php', 
     contentType: 'application/x-www-form-urlencoded;charset=ISO-8859-7', 
     type : 'POST', 
     data : UrlToPass, 
     success: function(responseText) { 
        gridder.html(responseText); 
     } 
  }); 

}

在ajax.php中我有这段代码:

enter code here $action = $_POST['action'];  switch($action) { case "load": 

我看不到任何东西,只能加载...... 问题只出在ie8

1 个答案:

答案 0 :(得分:0)

IE8在使用jQuery's html()

插入长字符串时遇到问题

可能这是一个已知的错误。您可以参考this

方法是

try {
    //new browsers
    $('#domElement').html(responseText);
} catch (e) {
    //IE8
    $('#domElement').innerHTML = responseText;
}

修改-1

function LoadGrid() { 
 // var gridder = $('#as_gridder'); 
  var UrlToPass = "action=load"; 
  //was var UrlToPass = 'action=load'; 
  gridder.html('loading..');       
  $.ajax({ 
     url : 'cartajax.php', 
     contentType: 'application/x-www-form-urlencoded;charset=ISO-8859-7', 
     type : 'POST', 
     data : UrlToPass, 
     success: function(responseText) { 
        try{
            $('#as_gridder').html(responseText);
        } catch (e) {
            //IE8
            $('#as_gridder').innerHTML = responseText;
        }
     } 
  }); 
}