php - jquery is resetting my div content -
i'm trying change content of div using jquery. content flashes , resets div. cannot use return false;
because there button post text field value. want keep changes of div. here code:
<html> <head> <meta charset="utf-8"> <title></title> <script type="text/javascript" src="jquery.js"></script> </head> <body> <div> <form id="form" method="post"> <input type="text" name="gname" id="gname"/></br> <button id="btn">set</button> <button id="nbtn">view</button> </form> </div> <div id="outp"> </div> </body> <script> $("#btn").click(function(event) { $.post("send.php", { named: $("#gname").val()}, function(data) { alert(data); }); }); </script> <script> $("#nbtn").click(function(e) { $("#outp").html("<?php include './view.php'; ?>"); }); </script>
it's not jquery; it's form being posted. change made, form posted , page refreshed server.
the default type of button
elements "submit"
. make 1 or both of buttons button, use type="button"
.
alternately, if want allow form used when javascript disabled (e.g., allow posted normally), leave buttons submit buttons prevent form submission using javascript. e.g.:
$("#form").submit(false); // prevents form being submitted in normal way.
Comments
Post a Comment