Jquery ajax JSON不能在我的网页上使用我的网页

if I use the Jquery Ajax function to parse the last.fm API work all fine.

Jquery function:

$.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 />");
        });
    } 
}

But if I Copy the JSON results of the LAST.FM url page in a php file on my server don't work:

PHP Page

<?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 function:

$.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 />");
        });
    } 
}

Why?

You should build a PHP Array containing all your data. Then use json_encode($theArray) , it should convert the array into a JSON Array