代码在JsFiddle上有效,但在网站上无效 [英] Code works on JsFiddle but not on website

查看:117
本文介绍了代码在JsFiddle上有效,但在网站上无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在jsFiddle中运行的代码在我的网站上运行.

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.

这是我的页面页面结构

<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

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告诉我,Uncaught SyntaxError:第32行出现意外的令牌ILLEGAL.

Firebug tells me that Uncaught SyntaxError: Unexpected token ILLEGAL on line 32.

这是完整页面的网址 http://ipwtclothing.net/test.html

花了几天时间,所以我们将不胜感激.谢谢.

Been on this for a few days so any help would be appreciated. Thanks.

推荐答案

错误似乎来自文件末尾的多余字符.如果删除该字符,则文件可以正常工作.

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.

我试图将您的网页保存在本地并离线打开.我遇到了同样的问题.然后,以后我可以在js的最后一行识别出无效字符.

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>

以上是我在vim编辑器中看到的方法.删除最后一个特殊字符,这将解决您的问题.

The above is how i could see in vim editor. Remove that last special character and that will fix you the problem.

这篇关于代码在JsFiddle上有效,但在网站上无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆