Categories
jQuery

Include multiple js files using jQuery $.getScript() method

The jQuery getScript() method is used to Include multiple js files i.e. load and execute a JavaScript from the server using an AJAX HTTP GET request. The method returns XMLHttpRequest object and the callback is fired once the script has been loaded, but not necessarily executed. Syntax of getScript: $(selector).getScript(url,success(response,status)) $.getScript( “test.js”, function( data, textStatus, […]

Categories
jQuery

Parse json data with jquery

jQuery parseJSON() takes a well formed JSON string and then returns the resulting JavaScript value. Prior to jQuery 1.9 version, $.parseJSON returned null value rather than throwing an error if this was passed an empty string, null, or undefined, even though those are not valid JSON. Here are some basic things about JSON: JSON is […]

Categories
jQuery

Load JSON encoded data using jQuery.getJSON()

Using jQuery.getJSON method you can get or load JSON encoded data by an AJAX HTTP GET request. The method returns XMLHttpRequest object. JSON stands for JavaScript Object Notation. So, this is a way of formatting the data to look at loading JSON data using an HTTP GET request (you can also use POST method). Syntax: […]

Categories
jQuery

Download a HTML content as pdf using javascript – jsPDF

Using jsPDF library, you can download the div containing graphs, tables, contents as a PDF. This is a HTML5 client-side solution for generating PDFs. Simply include library in your <head>, generate your PDF using the many built-in functions, then create a button to trigger the download. <script type=”text/javascript” src=”http://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.min.js”></script> Create a object: var doc = […]

Categories
jQuery

jQuery Makes Parsing XML Easy

jQuery.parseXML uses native parsing function of the browser to create a valid XML document. After that this document can then be passed to jQuery for creating a typical jQuery object which can be traversed and manipulated then. This is a easy technique of parsing JSON with jQuery and thought i’d pick this up and show […]

Categories
jQuery

.empty() vs .remove() vs .detach() – jQuery

jQuery provides various methods to remove elements from DOM i.e. .empty(), .remove() and .detach(). So lets find out the difference between jQuery .empty(), .remove() and .detach() method. .empty(): jQuery .empty() method removes all the child element of the matched element where remove() method removes set of matched elements from DOM. $( “.content” ).empty(); remove(): jQuery […]

Categories
jQuery

jQuery post() Method – load data from the server

jQuery post() Method loads data from the server using a HTTP POST request. Syntax: $(selector).post(URL, data, function(data,status,xhr), dataType) Example of jQuery post(): $.post( “ajax-master.php”, function( data ) { $( “#result” ).html( data ); }); The above example fetches the requested HTML snippet and inserts it on the page based on ID. Read also: Abort Ajax […]

Categories
jQuery

Difference between $.each(selector) and $(selector).each()

In jQuery, there is an object iterator utility called $.each() as well as a jQuery collection iterator: .each() to run for each matched element. We can return false to stop the loop early. Syntax: $(selector).each(function(index,element)) Basically, $.each() is essentially a drop-in replacement of a traditional for or for-in loop. So, .each is an iterator which […]

Categories
jQuery

Abort Ajax requests using jQuery

Using jQuery abort() you can cancel a running AJAX request forcefully before it ends as this hits several times within a short time period. This is usually in cases where the user might perform an action, based on AJAX request several times within a short time period. For example, There is a auto-complete functionality for […]

Categories
Javascript jQuery

Difference between window.location.href and location.reload

window location href and location reload() both redirects a page to a new page but there are some difference to follow. Here is the difference between window.location.href and location.reload: window.location.href is not a method. It is a property which will tell you the current URL location of the browser. Changing the value of the property […]