Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中更新引导打印头中的数据源_Javascript_Ajax_Twitter Bootstrap - Fatal编程技术网

在javascript中更新引导打印头中的数据源

在javascript中更新引导打印头中的数据源,javascript,ajax,twitter-bootstrap,Javascript,Ajax,Twitter Bootstrap,我希望下拉选项反映存储在名为companyinfo.js的文件中的数组中的所有项,我通过ajax请求该文件。当页面加载时,我调用dropDownList() function dropDownList (evt) { console.log("dropdownfired"); var companyArray = []; $.ajax({ url : 'assets/data/companyarray.js', //this file is just ["

我希望下拉选项反映存储在名为companyinfo.js的文件中的数组中的所有项,我通过ajax请求该文件。当页面加载时,我调用
dropDownList()

function dropDownList (evt) {
    console.log("dropdownfired");
    var companyArray = [];
    $.ajax({
        url : 'assets/data/companyarray.js', //this file is just ["Facbeook", "Twitter", "Klout",]
        dataType: 'script',
        success: function(data) {
            companyArray = data;
            console.log(companyArray); //returns an array of the companies
            $('#companyInput1').attr('data-source', companyArray); //#companyInput1 is the input field where I want the typehead to be
            console.log($('#companyInput1').attr('data-source')); //returns undefined
        }
    });
}
更新:

function dropDownList (evt) {
    console.log("dropdownfired");
    var companyArray = [];
    $.ajax({
        url : 'assets/data/companyarray.js', //this file is just ["Facbeook", "Twitter", "Klout",]
        dataType: 'script',
        success: function(data) {
            companyArray = data;
           console.log(companyArray); // gives array of companies
            $('#companyInput1').data('data-source', companyArray);
            console.log($('#companyInput1').data('data-source')); // gives undefined still
        }
    });
}​

您不应该在HTML节点上存储字符串以外的任何内容作为属性。要存储数组,请使用jquery提供的

success: function(data) {
        companyArray = data;
        console.log(companyArray); //returns an array of the companies
        $('#companyInput1').data('data-source', companyArray); //#companyInput1 is the input field where I want the typehead to be
        console.log($('#companyInput1').data('data-source')); //should work
    }

出于某种原因,这仍然不起作用。查看我上面更新的代码