Php Jquery-ajax-JSON-don';我不能用我的网页在我的Web服务器上工作

Php Jquery-ajax-JSON-don';我不能用我的网页在我的Web服务器上工作,php,jquery,json,Php,Jquery,Json,如果我使用Jquery Ajax函数来解析last.fm API,一切正常 Jquery函数: $.ajax({ url: "http://ws.audioscrobbler.com/2.0/?method=album.search&album=believe&limit=2&api_key=b25b959554ed76058ac220b7b2e0a026&format=json", cache: true, dataType: "json

如果我使用Jquery Ajax函数来解析last.fm API,一切正常

Jquery函数:

$.ajax({
    url: "http://ws.audioscrobbler.com/2.0/?method=album.search&album=believe&limit=2&api_key=b25b959554ed76058ac220b7b2e0a026&format=json",
    cache: true,
    dataType: "json",
    success: function(data_album) {
        $.each(data_album.results.albummatches.album, function(a_album,res_album){
            $("#search-album").append("Album: "+(a_album+1)+" :"+res_album.name+"<hr />");
        });
    } 
}
$.ajax({
    url: "mypage.php",
    cache: true,
    dataType: "json",
    success: function(data_album) {
        $.each(data_album.results.albummatches.album, function(a_album,res_album){
            $("#search-album").append("Album: "+(a_album+1)+" :"+res_album.name+"<hr />");
        });
    } 
}
$.ajax({
url:“http://ws.audioscrobbler.com/2.0/?method=album.search&album=believe&limit=2&api_key=b25b959554ed76058ac220b7b2e0a026&format=json",
是的,
数据类型:“json”,
成功:功能(数据集){
$.each(数据相册.results.albummatches.album,函数(a相册,res相册){
$(“#搜索相册”).append(“相册:+(a#album+1)++”:“+res#album.name+”
); }); } }
但是,如果我在服务器上的php文件中复制最后一个.FM url页面的JSON结果,则无法工作:

PHP页面

<?php header('content-type: application/json; charset=utf-8');
    echo '{"results":{"opensearch:Query":{"#text":"","role":"request","searchTerms":"believe","startPage":"1"},"opensearch:totalResults":"2523","opensearch:startIndex":"0","opensearch:itemsPerPage":"2","albummatches":{"album":[{"name":"Believe","artist":"Disturbed","id":"1418894","url":"http:\/\/www.last.fm\/music\/Disturbed\/Believe","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34s\/53553281.png","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/53553281.png","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/53553281.png","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/53553281.png","size":"extralarge"}],"streamable":"1","mbid":"ed32813a-cd20-4bb3-b3fd-bca6161deb17"},{"name":"Make Believe","artist":"Weezer","id":"2025180","url":"http:\/\/www.last.fm\/music\/Weezer\/Make+Believe","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34s\/53692665.png","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/53692665.png","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/53692665.png","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/53692665.png","size":"extralarge"}],"streamable":"1","mbid":"f4fe4c6a-d5b8-45a5-b24f-2c3b9dda8811"}]},"@attr":{"for":"believe"}}}';
?>

Jquery函数:

$.ajax({
    url: "http://ws.audioscrobbler.com/2.0/?method=album.search&album=believe&limit=2&api_key=b25b959554ed76058ac220b7b2e0a026&format=json",
    cache: true,
    dataType: "json",
    success: function(data_album) {
        $.each(data_album.results.albummatches.album, function(a_album,res_album){
            $("#search-album").append("Album: "+(a_album+1)+" :"+res_album.name+"<hr />");
        });
    } 
}
$.ajax({
    url: "mypage.php",
    cache: true,
    dataType: "json",
    success: function(data_album) {
        $.each(data_album.results.albummatches.album, function(a_album,res_album){
            $("#search-album").append("Album: "+(a_album+1)+" :"+res_album.name+"<hr />");
        });
    } 
}
$.ajax({
url:“mypage.php”,
是的,
数据类型:“json”,
成功:功能(数据集){
$.each(数据相册.results.albummatches.album,函数(a相册,res相册){
$(“#搜索相册”).append(“相册:+(a#album+1)++”:“+res#album.name+”
); }); } }

为什么?

您应该构建一个包含所有数据的PHP数组。
然后使用
json\u encode($theArray)
,它应该将数组转换成一个json数组

什么是“不工作的”?请更具体一点……只需说“这是我的代码,它不工作”不是我们可以处理的东西。它在做什么?它应该做什么?你遇到了哪些错误?等等。使用firebug检查http请求和响应回答“它不工作”是要求没有人查看你的问题。详细的错误消息允许其他人提供帮助。