Ajax Jquery 对象不像 javascript 的对象那样工作
Ajax Jquery object not working like javascript's object
我正在使用预输入 JS 在我的控件中设置预输入。
输入class个对象数组的代码是这样的:
var companylist2 = [
{ word: "Alabama" },
{ word: "Alaska" },
{ word: "Arizona" },
{ word: "Arkansas" },
{ word: "California" },
{ word: "Colorado" }
];
// Get Company Name Typeahead
var states = new Bloodhound({
datumTokenizer: function (d) {
return Bloodhound.tokenizers.whitespace(d.word);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 5,
local: companylist2
});
但是我想从我的后端动态设置它,所以我使用 Ajax Jquery 来填充一个 class 对象数组,如下所示:
$(function () {
$.ajax({
type: "POST",
url: "mypage.aspx/getCompanylist",
contentType: "application/json",
dataType: "json",
success: function (msg) {
companylist = msg.d;
alert(companylist[0]["word"]);
alert(companylist[1]["word"]);
}
});
});
companylist[0]["word"] 和 companylist[1]["word"] 的警报都显示了我希望它显示的内容,但是当我将来源更改为我的来源时JQuery,提前输入不起作用
尝试在 success
中配置 Typeahead
$(function () {
$.ajax({
type: "POST",
url: "mypage.aspx/getCompanylist",
contentType: "application/json",
dataType: "json",
success: function (msg) {
companylist = msg.d;
alert(companylist[0]["word"]);
alert(companylist[1]["word"]);
// Get Company Name Typeahead
var states = new Bloodhound({
datumTokenizer: function (d) {
return Bloodhound.tokenizers.whitespace(d.word);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 5,
local: companylist
});
}
});
});
也许Callback and Asynchronous有帮助。
我正在使用预输入 JS 在我的控件中设置预输入。
输入class个对象数组的代码是这样的:
var companylist2 = [
{ word: "Alabama" },
{ word: "Alaska" },
{ word: "Arizona" },
{ word: "Arkansas" },
{ word: "California" },
{ word: "Colorado" }
];
// Get Company Name Typeahead
var states = new Bloodhound({
datumTokenizer: function (d) {
return Bloodhound.tokenizers.whitespace(d.word);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 5,
local: companylist2
});
但是我想从我的后端动态设置它,所以我使用 Ajax Jquery 来填充一个 class 对象数组,如下所示:
$(function () {
$.ajax({
type: "POST",
url: "mypage.aspx/getCompanylist",
contentType: "application/json",
dataType: "json",
success: function (msg) {
companylist = msg.d;
alert(companylist[0]["word"]);
alert(companylist[1]["word"]);
}
});
});
companylist[0]["word"] 和 companylist[1]["word"] 的警报都显示了我希望它显示的内容,但是当我将来源更改为我的来源时JQuery,提前输入不起作用
尝试在 success
$(function () {
$.ajax({
type: "POST",
url: "mypage.aspx/getCompanylist",
contentType: "application/json",
dataType: "json",
success: function (msg) {
companylist = msg.d;
alert(companylist[0]["word"]);
alert(companylist[1]["word"]);
// Get Company Name Typeahead
var states = new Bloodhound({
datumTokenizer: function (d) {
return Bloodhound.tokenizers.whitespace(d.word);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 5,
local: companylist
});
}
});
});
也许Callback and Asynchronous有帮助。