我在chromium上不断收到这个错误,但在Firefox上却没有,它快把我逼疯了,因为我已经找了好几个小时也找不到解决方案。我基本上是从服务器获取JSON,然后将其插入到DOM中。这是我的代码。
function lookup(inputString){
if(inputString.length == 0){ //hide suggestions
$('#suggestions').empty()
.fadeOut();
}
else{ //make an AJAX call
$.ajax({
type: 'GET',
url: '{% url "search.views.search" inputString="xyz" %}'.replace("xyz", inputString.toString()),
dataType: 'json',
success: function(search_results){
suggestions = JSON.parse(JSON.stringify(search_results));
alert(suggestions[0].name);
}
})
}
}发布于 2013-10-22 02:47:28
在这段代码的末尾,您需要一个;:
$.ajax({
type: 'GET',
url: '{% url "search.views.search" inputString="xyz" %}'.replace("xyz", inputString.toString()),
dataType: 'json',
success: function(search_results){
suggestions = JSON.parse(JSON.stringify(search_results));
alert(suggestions[0].name);
}
});发布于 2013-10-22 02:59:32
相同的结论:)
您漏掉了一个分号;
jslint可以帮助你找到这样的错误:http://www.jslint.com/
function lookup(inputString) {
if (inputString.length === 0) {
$('#suggestions').empty().fadeOut();
}
else {
$.ajax({
type: 'GET',
url: '{% url "search.views.search" inputString="xyz" %}'.replace("xyz", inputString.toString()),
dataType: 'json',
success: function(search_results) {
suggestions = JSON.parse(JSON.stringify(search_results));
alert(suggestions[0].name);
}
});
}
}https://stackoverflow.com/questions/19502189
复制相似问题