Further to my earlier post jQuery Document Ready…use it wisely! one reader pointed out a different kind of architecture:
The html, test1.html:
<html> <head> <title>Document Ready Demo</title> <script src = "jquery-1.4.2.js"></script> <script src = "test1.js"></script> <script> $(document).ready(function () { //make sure there is no caching to avoid confusion $.ajaxSetup({cache: false}); $('#fetchView1').click(function () { $.get('view1.html', function (data) { $('#viewText1').html(data); }); }); }); </script> </head> <body> <button id = "fetchView1">Fetch View1</button> <div id = "viewText1"> View1 content goes here </div> </body> </html>
When the button is clicked, an AJAX call is made. This call fetches the contents of view1.html and puts it in the div with id viewText1. Now let’s look at the view:
view1.html:
<div> <input type="text" id="inputView1" value="Click button to fill with 1111" size="50" /> <button id="buttonView1">Fill Input with number 1111</button> </div>
[…] previous post jQuery Document Ready, the saga continues… got me thinking. Why not write a jQuery plugin which simulates a ready handler tied to an AJAX […]
LikeLike