$.ajax not loading data data everytime from server

Posted by Ted on Stack Overflow See other posts from Stack Overflow or by Ted
Published on 2010-04-03T13:37:15Z Indexed on 2010/04/03 13:43 UTC
Read the original article Hit count: 282

Filed under:
|
|
|
|

I have written a simple jQuery.ajax function which loads a user control from the server on click of a button. The first time I click the button, it goes to the server and gets me the user control. But each subsequent click of the same button does not goes to the server to fetch me the user control.

Since my user control fetches data from db, I need to reload the user control everytime i hit the button. But if anyhow I get my user control to unload from the page, and re-click the button, it goes to the server and fetches me the user control. Here's the code:


$("#btnLoad").click(function() {
    if ($(this).attr("value") == "Load Control") {
 $.ajax({
  url: "AJAXHandler.ashx",
  data: { "lt": "loadcontrol" },
  dataType: "html",
  success: function(data) {
   content.html(data);
  }
 });
 $(this).attr("value", "Unload Control");
    }
    else {
 $.ajax({
  url: "AJAXHandler.ashx",
  data: { "lt": "unloadcontrol" },
  dataType: "html",
  success: function(data) {
   content.html(data);
  }
 });
 $(this).attr("value", "Load Control");
    }
});

Please let me know if there is any other way I can get my user control loaded from server everytime I click the button.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about load