我有一个包含两个单元格的HTML表来搜索自动完成输入: HTML如下
$('#address1').focus(function() {
$.ajax({
url:"../phpAssets/StnList.php",
method:"POST",
success:function(data){
availableStns = jQuery.parseJSON(new Array(data));
window.alert(data);
$('#address1').autocomplete({
source: availableStns
});
}
});
}); //The Line where the Browser throws error
$('#fileRef').focus(function() {
var selectedSection = $('#section option:selected');
var selsec = selectedSection.val();
$.ajax({
url:"../phpAssets/fileRefList.php",
method:"POST",
data:{selsec:selsec},
success:function(data){
availableFileRefs = jQuery.parseJSON(new Array(data));
$('#fileRef').autocomplete({
source: availableFileRefs
});
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<thead>
<tr>
<th scope="col" style="width: 200px;">File Reference</th>
<th scope="col">Address</th>
</tr>
</thead>
<tbody>
<tr>
<td><input name ="fileRef" id="fileRef" class="form-control ui-autocomplete-input" autocomplete="on"></td>
<td name ="address1" id="address1"><input name ="address1" id="address1" class="form-control ui-autocomplete-input" autocomplete="on"></td>
</td>
</tr>
</tbody>
</table>
代码在语法上是正确的,但浏览器抛出以下错误:
Uncaught SyntaxError: Unexpected token }
这是第一个.focus()函数结束的行。尽我所能但却无法理解原因。
答案 0 :(得分:0)
我不知道发生了什么变化。我只是将相关代码部分复制到另一个.php并测试它并将其复制回主项目文件。 Stuff现在正在运作。这是(修改,如果我可以说)脚本:
<script>
$(function() {
$( "#datepicker" ).datepicker({dateFormat: 'dd M y' });
});
$('#address1').focus(function() {
$.ajax({
url:"../phpAssets/StnList.php",
method:"POST",
success:function(data){
availableStns = jQuery.parseJSON(new Array(data));
$('#address1').autocomplete({
source: availableStns
});
}
});
}); //The Line where the Browser throws error
$('#fileRef').focus(function() {
var selectedSection = $('#section option:selected');
var selsec = selectedSection.val();
$.ajax({
url:"../phpAssets/fileRefList.php",
method:"POST",
data:{selsec:selsec},
success:function(data){
availableFileRefs = jQuery.parseJSON(new Array(data));
$('#fileRef').autocomplete({
source: availableFileRefs
});
}
});
});
</script>