Bootstrap 3 – How to load content in modal body via AJAX?

This is actually super simple with just a little bit of added javascript. The link’s href is used as the ajax content source. Note that for Bootstrap 3.* we set data-remote=”false” to disable the deprecated Bootstrap load function. JavaScript: // Fill modal with content from link href $(“#myModal”).on(“show.bs.modal”, function(e) { var link = $(e.relatedTarget); $(this).find(“.modal-body”).load(link.attr(“href”)); … Read more

Google Chrome –allow-file-access-from-files disabled for Chrome Beta 8

Looking at the issues for this shows that the whole –allow-file-access-from-files thing was rushed. “Firefox does it..” “How can we do it?” some time passes “Here are the patches” “Passes! On trunk wonder what happens in the next dev release” “Ahhh it’s broken” “Use the command line option” “ok” “We shipped!” “WTF guys? You broke … Read more

Call jQuery Ajax Request Each X Minutes

You can use the built-in javascript setInterval. var ajax_call = function() { //your jQuery ajax code }; var interval = 1000 * 60 * X; // where X is your every X minutes setInterval(ajax_call, interval); or if you are the more terse type … setInterval(function() { //your jQuery ajax code }, 1000 * 60 * … Read more

Why use AJAX when WebSockets is available?

WebSockets isn’t intended to replace AJAX and is not strictly even a replacement for Comet/long-poll (although there are many cases where this makes sense). The purpose of WebSockets is to provide a low-latency, bi-directional, full-duplex and long-running connection between a browser and server. WebSockets opens up new application domains to browser applications that were not … Read more

How can I catch and process the data from the XHR responses using casperjs?

This is not easily possible, because the resource.received event handler only provides meta data like url, headers or status, but not the actual data. The underlying phantomjs event handler acts the same way. Stateless AJAX Request If the ajax call is stateless, you may repeat the request casper.on(“resource.received”, function(resource){ // somehow identify this request, here: … Read more

How do I detect if a user has got to a page using the back button?

Use a hidden form. Form data is preserved (typically) in browsers when you reload or hit the back button to return to a page. The following goes in your page (probably near the bottom): <form name=”ignore_me”> <input type=”hidden” id=”page_is_dirty” name=”page_is_dirty” value=”0″ /> </form> In your javascript, you will need the following: var dirty_bit = document.getElementById(‘page_is_dirty’); … Read more