2013-02-02 23 views
2

我用下面的代码来填充数据组合框。它适用于Firefox和Google Chrome,但不适用于IE8。在IE8中不工作组合框

$.ajax({ 
    type: "POST", url:"reg/data/data.php", 
    data: { 
     cat:"Y", 
     //toUser: "4", 
     // ignoreMessages:"1 
    }, 
    success: function(data){ 
     $.each(data, function (i, elem) { 
      $('#catogery').append(new Option(elem.id)); 
      //console.log(elem); 
     });    
    } 
}); 

PHP:

$result = mysql_query("SELECT DISTINCT CATCODE from subjectmaster"); 

$messages; 

header('Content-type: application/json'); 

$return_arr = array(); 

while($row = mysql_fetch_array($result)) { 
    $row_array['id']=$row[0]; 
    array_push($return_arr,$row_array); 
} 

echo json_encode($return_arr); 
+0

我取消注释但仍然与以前一样,为什么它只发生在IE –

回答

0

从猫后删除逗号:

$.ajax({ 
type: "POST", url:"reg/data/data.php", 
data: { 
    cat:"Y" 

}, 
success: function(data){ 
    $.each(data, function (i, elem) { 
     $('#catogery').append(new Option(elem.id)); 
     //console.log(elem); 
    });    
} 

});

+0

我试过了,但它和以前一样。 –

+0

如果我在不使用cat变量的情况下调用php文件会发生什么 –

+0

是否有任何javascript错误显示在ie 8中 – mjdevloper

0

您在数据数组中提到了“,”,之后没有元素。删除“,”它应该工作。

data: { 
    cat:"Y", //<------Remove this comma 
    //toUser: "4", 
    // ignoreMessages:"1 
}