【发布时间】:2011-10-10 17:09:26
【问题描述】:
我有两个文件。
location.php, that outputs this:
[["javascript"],["PHP"]]
在另一个文件中:
<script type="text/javascript">
$.getJSON('location.php', function(data) {
var sampleTags = [];
$.each(data, function(key, val) {
sampleTags.push(val);
});
alert(sampleTags); // show javascript, php
//-------------------------------
// Preloading data in markup
//-------------------------------
$('#myULTags').tagit({
availableTags : sampleTags, // this param is of course optional. it's for autocomplete.
// configure the name of the input field (will be submitted with form), default: item[tags]
itemName : 'item',
fieldName : 'tags'
});
});
</script>
自动完成不起作用。为什么?
如果我使用:
var sampleTags = [ 'javascript', 'php'];
一切正常,但使用 json 时,自动完成功能根本不起作用。
【问题讨论】:
标签: php javascript jquery json