我有一个接一个的3个ajax调用,它们调用各自的Web服务。这些Web服务返回parseJSON对象。在所有3个ajax调用中,我使用这些parseJSON对象值填充下拉列表。但它只填充第1和第3列表而不是第2列表。那么问题是什么?
我的代码如下。
<script type="text/javascript">
$(document).ready(function () {
//For test
$ConUrl = 'http://mydomain.com/WebService.asmx/FetchCountry?callback=parseJSON?';
$StateUrl = 'http://mydomain.com/WebService.asmx/FetchState?callback=parseJSON?';
$CityUrl = 'http://mydomain.com/WebService.asmx/FetchCity?callback=parseJSON?';
populateCountries();
}); // ready end
function populateCountries() {
$.ajax({
type: 'GET',
url: $ConUrl,
processData: true,
data: {},
dataType: "jsonp",
jsonpCallback: 'parseJSON',
success: function (data) {
var html = '<option value="0">All Regions</option>';
var len = data.length;
for (var i = 0; i < len; i++) {
html += '<option value="' + data[i] + '">' + data[i] + '</option>';
}
$('select#ddlCountry').append(html);
populateStates();
},
error: function (data) { }
});
}
function populateStates() {
$.ajax({
type: 'GET',
url: $StateUrl,
processData: true,
data: {},
dataType: "jsonp",
jsonpCallback: 'parseJSON',
success: function (data1) {
var html1 = '<option value="0">All States</option>';
var len1 = data1.length;
for (var j = 0; j < len1; j++) {
html1 += '<option value="' + data1[j] + '">' + data1[j] + '</option>';
}
$('select#ddlState').append(html1);
populateCities();
},
error: function (data1) { }
});
}
function populateCities() {
$.ajax({
type: 'GET',
url: $CityUrl,
processData: true,
data: {},
dataType: "jsonp",
jsonpCallback: 'parseJSON',
success: function (data2) {
var html2 = '<option value="0">All Cities</option>';
var len2 = data2.length;
for (var k = 0; k < len2; k++) {
html2 += '<option value="' + data2[k] + '">' + data2[k] + '</option>';
}
$('select#ddlCity').append(html2);
},
error: function (data2) { }
});
}
</script>
答案 0 :(得分:0)
问题已解决......问题不在于jquery ....它在标签中....
我写的如下......
<select id="ddlCountry" class="searchbox roundedcornerstyle" style="width:160px;" />
<select id="ddlState" class="searchbox roundedcornerstyle" style="width:160px;" />
<select id="ddlCity" class="searchbox roundedcornerstyle" style="width:160px;" />
在改变上面的行之后,git解决了......
<select id="ddlCountry" class="searchbox roundedcornerstyle" style="width:160px;"></select>
<select id="ddlState" class="searchbox roundedcornerstyle" style="width:160px;"></select>
<select id="ddlCity" class="searchbox roundedcornerstyle" style="width:160px;"></select>
找到这个真的花了太多时间..但最后却解决了......