I am using Firefox V26.0. A JavaScript will always place an event on all links to make an ajax call on click and load the page asynchronous. The content which will be loaded will be a JSON-string. It´ll parse the string to have all informations (content, page_title and uri). After that my script calls window.history.pushstate() to change the history of the browser. And then the error is in the source code. The loaded json string will be visible inside the source code in Firefox V26.0. This only appears if I have the window.history.pushstate() inside my AJAX-success-function. So be sure, the problem is not
$('#ajax_load').html(obj.content);
because the error occurs also if this line will be commented out. The loaded JSON will be visible in the source code only if I use pushState()
I really don't know why this appears.
Here is the full code. I only use this script in combination with jQuery, so no other scripts could affect the problem
// In combination with jquery-1.9.1.min.js
$(document).ready(function(){
$('body').addClass('js');
$.ajaxLoad = function(href, popstate){
popstate = typeof popstate !== 'undefined' ? popstate : true;
$.ajax({
type: 'GET',
url: href,
async: false,
success: function(json){
var obj = JSON && JSON.parse(json) || $.parseJSON(json);
/**
obj will look like
{
content : "content",
page_title: "Title of Page",
uri : "/path/to/appliction/"
}
*/
$('#ajax_load').html(obj.content);
if(popstate == true){
window.history.pushState({}, obj.page_title, obj.uri);
}
document.title = obj.page_title;
return false;
},
error: function(XMLHttpRequest, textStatus, errorThrown){
console.log(XMLHttpRequest);
return false;
}
});
}
$(document).on("click", 'a:not(".noAjaxLoad")', function(e){
e.preventDefault();
$.ajaxLoad($(this).attr("href"), true);
});
});
What if you try with only:
var obj = $.parseJSON(json);
It sounds like you are using pushState
to set the URI to the URI of the JSON data.
You need to set it to the URI of the page that you are transforming the original page into (using the data you get from JSON).
If you aren't already, then you need to create that page (probably by duplicating the work the client-side JS is doing with server side code).