Tuesday, September 24, 2013

JQuery weird bug variable not null after load() called

Today my web based application did something weird, the variable in div element doesnt nulled after load().
<div id = "content">
<input type = "text" id = "name">
<input type = "button" id = "submit">
</div>

$(document).ready(function(){
     $("#submit").click(function(){
        $("#content").load("./part/add_name.php", {
            'name' : $("#name").val()
        });
    });
});

You can still get value name input after load() to content div.

Possible solution is always call empty.
Example : 
$("#content").empty().load("./part/add_name.php", {
      'name' : $("#name").val()
});

No comments:

Post a Comment