我有一个jQuery Ajax函数,可以从json数据创建多个链接列表。它适用于所有Web浏览器IE,FF,Safari,Chrome,Opera,适用于iPhone,iTouch和iPad。出于某种原因,它无法在Android上运行:
function FetchListsMobTest(thislist) {
var thislist;
if (thislist == "comp") {
$('<div id="wrapper"></div>').html('<div id="comp1"><div id="companies"></div></div>').appendTo("#firstlist");
} if (thislist == "prod") {
$('<div id="wrapper"></div>').html('<div id="prod1"><div id="products"></div></div>').appendTo("#secondlist");
} if (thislist == "stan") {
$('<div id="wrapper"></div>').html('<div id="stan1"><div id="standards"></div></div>').appendTo("#thirdlist");
} if (thislist == "cert") {
$('<div id="wrapper"></div>').html('<div id="cert1"><div id="certified"></div></div>').appendTo("#fourthlist");
}
var Params = {};
Params.type = "get",
Params.url = "javascript/directories.js",
Params.data = "data",
Params.dataType = "json",
Params.cache = false,
Params.contentType = "application/json",
Params.processData = true,
Params.callbackParameter = "callback",
Params.error = function (xhr, textStatus, errorThrown) { alert(xhr.errorThrown); },
Params.success = function (data) {
$.each(data.directory, function (i, data) {
var Company2 = '' + data.Company + '';
var Product2 = '' + data.Product + '';
var Standard2 = '' + data.Standard + '';
var Certify2 = '' + data.Certified + '';
if (thislist == "comp") {
$('<div class="company" style="text-align:left;border-bottom: 1px solid #ccc;margin: 0px;padding-top: 0.5em;padding-left: 0.4em;padding-right: 0px;padding-bottom: 0.5em;font-size: 0.9em;line-height: 100%;"></div>').html('<a href="listingsMob.html?Company=' + Company2 + '" target="_top" style="text-decoration: none;padding-left: 10px;background-image: url(images/open_arrow.gif);background-position: bottom left;background-repeat: no-repeat;">' + Company2 + '</a>').appendTo("#companies");
} if (thislist == "prod") {
$('<div class="product" style="text-align:left;border-bottom: 1px solid #ccc;margin: 0px;padding-top: 0.5em;padding-left: 0.4em;padding-right: 0px;padding-bottom: 0.5em;font-size: 0.9em;line-height: 90%;"></div>').html('<a href="listingsMob.html?Product=' + Product2 + '" target="_top" style="text-decoration: none;padding-left: 10px;background-image: url(images/open_arrow.gif);background-position: bottom left;background-repeat: no-repeat;">' + Product2 + '</a>').appendTo("#products");
} if (thislist == "stan") {
$('<div class="standard" style="text-align:left;border-bottom: 1px solid #ccc;margin: 0px;padding-top: 0.5em;padding-left: 0.4em;padding-right: 0px;padding-bottom: 0.5em;font-size: 0.9em;line-height: 90%;"></div>').html('<a href="listingsMob.html?Standard=' + Standard2 + '" target="_top" style="text-decoration: none;padding-left: 10px;background-image: url(images/open_arrow.gif);background-position: bottom left;background-repeat: no-repeat;">' + Standard2 + '</a>').appendTo("#standards");
} if (thislist == "cert") {
$('<div class="certify" style="text-align:left;border-bottom: 1px solid #ccc;margin: 0px;padding-top: 0.5em;padding-left: 0.4em;padding-right: 0px;padding-bottom: 0.5em;font-size: 0.9em;line-height: 90%;"></div>').html('<a href="listingsMob.html?Certified=' + Certify2 + '" target="_top" style="text-decoration: none;padding-left: 10px;background-image: url(images/open_arrow.gif);background-position: bottom left;background-repeat: no-repeat;">' + Certify2 + '</a>').appendTo("#certified");
}
});
// because this is in a for each loop, it may list the returned variables multiple times so
// remove duplicate returned variable appearances
var mapAddedComany = {};
//alert('comes here');
$(".company").each(function () {
var value = $(this).text();
if (mapAddedComany[value] == null) {
mapAddedComany[value] = true;
} else {
$(this).remove();
}
});
var mapAddedProduct = {};
$(".product").each(function () {
var value = $(this).text();
if (mapAddedProduct[value] == null) {
mapAddedProduct[value] = true;
} else {
$(this).remove();
}
});
var mapAddedStandard = {};
$(".standard").each(function () {
var value = $(this).text();
if (mapAddedStandard[value] == null) {
mapAddedStandard[value] = true;
} else {
$(this).remove();
}
});
var mapAddedCertify = {};
$(".certify").each(function () {
var value = $(this).text();
if (mapAddedCertify[value] == null) {
mapAddedCertify[value] = true;
} else {
$(this).remove();
}
});
return false;
},
$.ajax(Params);
}
我一直在搜索论坛两天,无法弄清楚我做错了什么。任何帮助将不胜感激。