Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击浏览器上的“上一步”按钮显示原始脚本_Javascript_Jquery_Ruby On Rails_Ajax_Html5 History - Fatal编程技术网

Javascript 单击浏览器上的“上一步”按钮显示原始脚本

Javascript 单击浏览器上的“上一步”按钮显示原始脚本,javascript,jquery,ruby-on-rails,ajax,html5-history,Javascript,Jquery,Ruby On Rails,Ajax,Html5 History,页面中有一些ajax调用。我所做的是使用历史api来更新历史。在页面/test中,我发出一个ajax请求,更新历史记录,url设置为/test?query=true。在pop状态下,根据当前url进行ajax调用 // Called in click event for the ajax call to create the history. var stateObj = { query: 'query' }; history.pushState(stateObj, nu

页面中有一些ajax调用。我所做的是使用历史api来更新历史。在页面/test中,我发出一个ajax请求,更新历史记录,url设置为/test?query=true。在pop状态下,根据当前url进行ajax调用

// Called in click event for the ajax call to create the history.
      var stateObj = { query: 'query' };
      history.pushState(stateObj, null, ?query=true);

// Called on the popstate
window.onpopstate = function(event) {
    $.ajax({
        method: 'get',
        url: window.location.href,
        dataType: 'script'
    });
}
现在,当我将状态pused和url更新为/test?query=true时,我转到另一个页面/test2并单击browser back按钮,浏览器将显示来自js.erb文件的原始js代码