Off the Ridge code

Off the Ridge Code Newsletter


Starting with jQuery – Part 4

Published April 30, 2014 in jQuery - 0Comments

How to load html data from the server (Ajax style)

$(selector).load(url,data,callback) – loads data from the server and inserts the returned HTML into the DOM. 
The first parameter is mandatory, while the other two are optional.

1. Using just the first parameter: url.

2. Using the first two parameters: url and passing in JSON data.
     $(#FirstDiv).load(‘MyPage.html, {author:Homer});

3. Using the url and callback function:
        function(response, status, xhr){
          if(status == “error”){
         if(status == “success”){
             alert(“External content loaded successfully!”);


I’m including the sample files here. You can extract them and if you have IIS Express (usually comes with Visual Studio installation) you can run it without starting Visual Studio.

C:Program FilesIIS Express

and drop the files into the path pointed by the default website.

Good Luck!