Code works on JsFiddle but not on website

馋奶兔 提交于 2019-12-24 10:56:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!