我试图使用Ajax和JQuery填充下拉列表,但是没有结果,因为我将查询限制在没有重音的某行时检测到的重音字符和一些特殊字符我得到了一些结果。这是我的代码:
JS:
var descwr=document.getElementById("descwr").innerHTML;
document.getElementById("descwr").innerHTML="<select id='descwr_text' ><option value='"+id+"'>"+codewr+" "+descwr+"</option></select>";
$.getJSON("get-data.php?d=car",function(data){
$.each(data,function(key,value) {
console.log(data);
$("#descwr_text").append($("<option></option>").val(value.ID).html(value.Code+"/"+value.Description));
});
});
PHP:
if(isset($_GET['d'])){
$dat=$_GET['d'];
if($dat=="car"){
$q = "SELECT ID,Code,Description from vehicules limit ";
$sql = mysql_query($q);
$data = array();
while($row = mysql_fetch_array($sql,true)){
$data[] = $row;
};
echo json_encode($data);
}
}