reload page source for AJAX request

I found that if I use AJAX calls on a page, the page source stays intact. This can cause problem, e.g. if user use forward/backward operation in a browser, when it backs to the page browser will have/read original HTML code and not the one with AJAX content. For example, let's say you construct a page with

<div id="foo">
<script type="text/javascript">
setTimeout('ajaxFunction', ...);

once you load the page, it will call ajaxFunction, which eventually will replace content of div tag with id="foo" (btw, it can be recursive calls as well). But the page source which you can view from the browser will still contains this snippet. Is there is any way to refresh page source without reloading the page?

I know that I can add page reload inside of my AJAX code, but I'd like to avoid it and not disturb end-users.


If you are taking about "view source" option available with right click - some browsers, if not all, are doing another request to get an HTML. Developer Tools/Firebug will show you updated HTML, but appears that after next/forward navigation initial HTML (without changes done with JS/AJAX) is shown. I thought that chrome will cache dynamic changes too but just checked this and it shows initial page. Suppose there is no way to change this behavior. The only way here, as for me, is to call ajaxFunction in document.onload if you want to be sure that the latest info is shown to user.

Browser is showing you the content which it received from server in HTTP response. All dynamic changes in DOM are not reflected there. So you can use firebug in FF or developer tools in Chrome to track dynamic changes.

Need Your Help

How to set some flags on my node build

node.js heroku codeship

When I build, test and deploy my node application from Codeship to Heroku I want to be able to set a release flag to true using a command line during the build. And in my code I want to do somethin...

Form validation evaluation

php forms validation

Please advise if the form validation script below is secure enough to avoid most types (all types?) of contact form exploits? I ahve found this script online, added some extra php finctions in hope...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.