这正常工作与XMLjQuery的.find与XML,但不是JSON工作
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://api.soundcloud.com/users/123/playlists.xml?client_id=ID",
dataType: "xml",
success: parse
});
});
function parse(xml) {
$(xml).find("playlists").each(function(){
//var title = $(this).find('title').text();
$("#catTitle").append($(this).text()+ "<br />");
});
}
但是当我改变这一点,这是行不通的。我在$(json).find("playlists").each(function(){
之后放了一个alert(),它永远不会被调用。有什么想法吗?
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://api.soundcloud.com/users/123/playlists.json?client_id=ID",
dataType: "json",
success: parse
});
});
function parse(json) {
$(json).find("playlists").each(function(){
//var title = $(this).find('title').text();
$("#catTitle").append($(this).text()+ "<br />");
});
}
无法搜索'json'与jQuery,这是一个JavaScript对象或数组。像使用JavaScript对象或数组一样使用它。 –
是的,我有一个想法,你为什么期望它的工作?它也不适用于XML,它只是发生XML有足够的类似于HTML的结构来欺骗JQuery – musefan
json没有格式化为使用.find()方法使用标记 –