0
我想加載到兩個不同的div的ajax,但我檢查控制檯和網頁仍然把數據放到一個div,即使它是在ajax代碼中調用兩個不同的div。我想加載到兩個不同的div的ajax
<script>$(document).ready(function(){
$.ajax({
url: "http://developer.api.cnet.com/rest/v1.0/techProductSearch",
type: "get",
data: { viewType:"json", iod: "none", callback: "phone", partKey:"2nnae6wsj2w72yqhcwu4v7sg", partTag:"2nnae6wsj2w72yqhcwu4v7sg", query: "iphone 5", productId:"31303113" },
dataType: "jsonp",
success: ipod
});
});
function ipod(data) {
var count = 0;
console.log(data);
$.each(data.CNETResponse.TechProducts.TechProduct, function(index,value) {
console.log("Name: "+data.CNETResponse.TechProducts.TechProduct[count].Name.$);
var datastring = '<tr>'+'<td class="searchItem">'+data.CNETResponse.TechProducts.TechProduct[count].Name.$+'</td> </tr>';
$('#tabs-1').append(datastring);
console.log("$('#tabs-1').append(datastring)");
count ++;
});
}</script>
<script>$(document).ready(function(){
$.ajax({
url: "http://developer.api.cnet.com/rest/v1.0/techProductSearch",
type: "get",
data: { viewType:"json", iod: "none", callback: "phone", partKey:"2nnae6wsj2w72yqhcwu4v7sg", partTag:"2nnae6wsj2w72yqhcwu4v7sg", query: "Samsung Note 3", productId:"31303113" },
dataType: "jsonp",
success: ipod
});
});
function ipod(data) {
var count = 0;
console.log(data);
$.each(data.CNETResponse.TechProducts.TechProduct, function(index,value) {
console.log("Name: "+data.CNETResponse.TechProducts.TechProduct[count].Name.$);
var datastring = '<tr>'+'<td class="searchItem">'+data.CNETResponse.TechProducts.TechProduct[count].Name.$+'</td> </tr>';
$('#tabs-2').append(datastring);
console.log("$('#tabs-2').append(datastring)");
count ++;
});
}</script>
HTML
<div id="tabs-1">
<p></p>
</div>
<div id="tabs-2">
<p></p>
</div>
其中之一,你有2個具有相同名稱的功能。嘗試鞏固你的代碼.. – kingkode
McMastermind說你有2個函數具有相同的名稱,最後一個聲明將覆蓋首先聲明的那個。將它們重命名爲具有唯一名稱 –
tr不是div的有效元素。 – epascarello