问题
I cannot get code that is working in jsFiddle to run on my site.
http://jsfiddle.net/tris_wood/qCqcK/
I have made adjustments to the code based on users here with the same issue but it still won't run.
Here is my page page structure
<head>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="custom.js"></script>
</head>
<div data-role="page">
<ul data-role="listview" id="results"></ul>
</div>
custom.js
$(document).ready(function() {
$.ajax({
url: "http://itunes.apple.com/lookup?id=300261471&entity=song",
dataType: 'jsonp',
success: function(json_results) {
console.log(json_results);
$('#results').append('<ul></ul>');
listItems = $('#results').find('ul');
$.each(json_results.results, function(key) {
// edit
var data = json_results.results[key],
artworkUrl60 = data.artworkUrl60 || '',
collectionViewUrl = data.collectionViewUrl || '',
collectionName = data.collectionName || '',
artistName = data.artistName || '',
trackName = data.trackName || '',
html = '<img src="' + artworkUrl60 + '"/>';
html += '<h3>' + collectionName + '</h3>';
html += '<p>' + artistName + '</p>';
html += '<p>' + trackName + '</p>';
listItems.append('<li><a href="' + collectionViewUrl + '">' + html + '</a>
</li>');
});
// Need to refresh list after AJAX call
$("#results").listview("refresh");
}
});
});
Firebug tells me that Uncaught SyntaxError: Unexpected token ILLEGAL on line 32.
Here is the url for the complere page http://ipwtclothing.net/test.html
Been on this for a few days so any help would be appreciated. Thanks.
回答1:
The error appears to be coming from an extraneous character residing at the end of your file. If you delete that character, the file works fine.
I tried to save your web page locally and open offline. I faced the same problem. Then later I could recognize a invalid character at the last line of js.
// Need to refresh list after AJAX call
$("#results").listview("refresh");
}
});
});<200b>
The above is how i could see in vim editor. Remove that last special character and that will fix you the problem.
来源:https://stackoverflow.com/questions/11870327/code-works-on-jsfiddle-but-not-on-website