我想使用jquery和ajax绑定下拉列表,并且我在页面加载时尝试调用方法。在我的代码下面
$(function () {
getCategoryDetails();
getCountryDetails();
});
在我的获取类别详细信息下面。它的作用就像空下拉列表并分配参数值和块UI以及调用下拉类别Appender方法
function getCategoryDetails() {
try {
$('#ddlCategory').empty().append('<option selected="selected" value="0">Select Category</option>');
categoryReq.PageIndex = 1;
categoryReq.objDetails.OrganizationID = LoggedinUserDetails.ID;
categoryReq.objDetails.OpType = 1;
blockUI();
dropdownCategoryAppender();
}
catch (err) {
messageProvider(0, err);
unBlockUI();
}
}
function dropdownCategoryAppender() {
try {
$.ajax({
type: 'POST',
url: '/pages/AddContact.aspx/GetCategoryDetails',
dataType: 'json',
data: JSON.stringify({ 'obj': JSON.stringify(categoryReq) }),
contentType: 'application/json; charset=utf-8',
success: function (data, textStatus, xhr) {
categoryRes = data.d;
categoryReq.IsMoreRecords = categoryRes.IsMoreRecords;
if (categoryRes.ReturnID >= 1) {
var ddl = $("[id*=ddlCategory]");
$.each(categoryRes.objDetails, function () {
ddl.append($("<option></option>").val(this.ID).html(this.Name));
});
unBlockUI();
}
else {
messageProvider(0, categoryRes.ReturnMsg);
unBlockUI();
}
if (categoryReq.IsMoreRecords) {
categoryReq.PageIndex++;
blockUI();
dropdownCategoryAppender();
}
},
error: function (xhr, textStatus, errorThrown) {
messageProvider(0, textStatus + ', ' + errorThrown);
unBlockUI();
}
});
}
catch (err) {
messageProvider(0, err);
unBlockUI();
}
}
上述方法工作正常,但下面的方法不起作用。 我正在获取国家/地区数据,然后我尝试将这些数据绑定到下拉列表但绑定过程跳过。
function getCountryDetails() {
try {
$('#ddlCountry').empty().append('<option selected="selected" value="0">Select Country</option>');
countryReq.PageIndex = 1;
countryReq.objDetails.OpType = 1;
blockUI();
dropdownCountryAppender();
}
catch (err) {
messageProvider(0, err);
}
}
function dropdownCountryAppender() {
try {
$.ajax({
type: 'POST',
url: '/pages/AddContact.aspx/GetCountryDetails',
dataType: 'json',
data: JSON.stringify({ 'obj': JSON.stringify(countryReq) }),
contentType: 'application/json; charset=utf-8',
success: function (data, textStatus, xhr) {
countryRes = data.d;
countryReq.IsMoreRecords = countryRes.IsMoreRecords;
if (countryRes.ReturnID >= 1) {
var ddl = $("[id*=ddlCountry]");
$.each(countryRes.objDetails, function () {
ddl.append($("<option></option>").val(this.ID).html(this.Name));
});
unBlockUI();
}
else {
messageProvider(0, countryRes.ReturnMsg);
unBlockUI();
}
if (countryReq.IsMoreRecords) {
countryReq.PageIndex++;
blockUI();
dropdownCountryAppender();
}
},
error: function (xhr, textStatus, errorThrown) {
messageProvider(0, textStatus + ', ' + errorThrown);
unBlockUI();
}
});
}
catch (err) {
messageProvider(0, err);
unBlockUI();
}
}
任何人对此都有任何想法请帮助我。
答案 0 :(得分:0)
$provide
见here。易于谷歌
答案 1 :(得分:-1)
试试这段代码
<body onload="myFunction();myFunction1();myFunction2()">