简体   繁体   English

相同代码的来源不同

[英]Identical code behaving differently from different sources

I have a very strange problem in which identical pieces of Javascript are behaving differently when being provided from different sources. 我有一个非常奇怪的问题,当从不同来源提供相同的Javascript片段时,它们的行为会有所不同。 The code is at the bottom of this post. 代码在这篇文章的底部。

The page this code is being used on is composed from two distinct sources: a standard view file and content (markup) from a database. 使用此代码的页面由两个不同的来源组成:标准视图文件和数据库中的内容(标记)。 The composition is done on the server side and sent to the client as unified document. 合成在服务器端完成,并作为统一文档发送到客户端。 So as far as the client is concerned, the page is the same. 因此,就客户端而言,页面是相同的。

The problem I'm having is this: when placed in the view file, the code executes normally and behaves as expected. 我遇到的问题是:当放置在视图文件中时,代码将正常执行并按预期方式运行。 However, when placed in the database, the browser reports missing } after function body . 但是,当放置在数据库中时,浏览器会missing } after function body报告missing } after function body

The code in the database and the view file is identical. 数据库和视图文件中的代码相同。 There is a single difference: when being placed in the database, all line breaks ( \\n ) are removed. 唯一的区别是:当放置在数据库中时,所有换行符( \\n )都将被删除。 Could this be the problem? 这可能是问题吗? If not, has anybody seen this kind of issue before? 如果没有,以前有人见过这种问题吗?

var rssTimeout = setTimeout(GetRSSFeed, 300000);
$(document).ready(function () {
    GetRSSFeed();
});

var GetRSSFeed = function () {
    var feedProxyURL = "http://localhost/BusinessLogicAPI/api/Proxy/RSSFeed?URL=http://feeds.bbci.co.uk/news/rss.xml";
    $.ajax({ url: feedProxyURL,
        type: "GET",
        dataType: "xml",
        success: function (data) {
            var xmData = $(data);

            //For the first 5 stories,
            //build some JSON data and give it to the templates
            xmData.children("rss")
                .children("channel")
                .children("item")
                .slice(0, 5)
                .each(function (I, E) {
                    var json = {};
                    json.title = $(E).children("title").text();
                    json.description = $(E).children("description").text();

                    $("#newsTemplate").tmpl(json).appendTo("#newsFeed");
                });
        },
        error: function () {
            $("#newsFeed").html("<span>Could not open feed</span>");
        }
    });
    rssTimeout = setTimeout("GetRSSFeed()", 300000);
};

Presumably the two // ... line comments cause the rest of the javascript to be commented out. 大概两个// ...行注释会导致其余的javascript被注释掉。 Remove the comments and see if it works? 删除评论,看看是否可行?

我们在javascript中注释了一行,但在IE9中检测到该行,而在IE8和Mozilla中却被注释为注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM