I have a very strange problem in which identical pieces of Javascript are behaving differently when being provided from different sources. 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.
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. 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. Remove the comments and see if it works?