在
PHP页面中,我有一个下拉列表,它触发jQuery更改功能并使用AJAX执行POST以填充页面中的第二个下拉列表.
它应该都非常简单,但Firebug会为’?’引发语法错误在运行时出现在我的代码中,实际上并不在我的代码中.
这是我的javascript代码:
$(document).ready(function() {
$('#taglist').change(function(){
$.ajax({
type: "POST",url: "../includes/ajax.PHP",data: "taglist=" + $(this).find("option:selected").attr('value'),dataType: 'json',success: function(response,textStatus,jqXHR) {
$("#catlist").html(response.catlist);
},error: function (xhr,errorThrown) {
$("#catlist").html(xhr.responseText);
}
});
});
});
以下是在ajax.PHP中执行的PHP代码:
if(isset($_POST['taglist'])){
$catlist = '<select name="cat_id[]" size="5" multiple id="cat_id[]">';
$catlist .= fillselecteditmultiple(0,$_POST['taglist']);
$catlist .= '</select>';
echo json_encode(array("status"=>"success","catlist" => $catlist));
}
fillselecteditmultiple()输出填充的选项,突出显示应该预先选择的选项.它工作正常,因为我在其他页面使用没有问题.为了确保它不是从函数本身抛出的错误,我甚至尝试更改函数以输出一个简单的$catlist =’abc’字符串作为响应,仍然是相同的错误.
奇怪的是,Firebug在javascript代码的最后两行抛出一个错误,就像你在附件中看到的那样:
可能导致“?”的原因是什么?出现在我的代码中?
只需检查您的编码.当你在一行的末尾看到“奇怪的”符号时,这可能主要是由编码问题引起的.
另外,常见建议:
When a program doesn’t kNow how to represent a unicode code point,it prints a question mark inside a square (I suppose you have seen this before),or in case it cannot,a simple question mark. An unexpected question mark always makes a developer SUSPECT of encoding. (c) Áxel