user11788312
user11788312

Reputation:

Jquery prevent page reload on post

I have the following pages edit_profile.php that is the page where the form is, and ajax/update_profile.php that is the page where data is sent via ajax.

 <script type="text/javascript">
            $(document).ready(function () {
              $("#update_profile").click(function() {
                  var updateprofile = $("#update_profile_form").serialize();
                     $.post(
                            "ajax/update_profile.php",
                            updateprofile
                     ).done(function(data) {
                            //alert("Successfully submitted!");
                            $("#result").html(data);


                     }).fail(function () {
                              //alert("Error submitting forms!");
                     })
              });
            });
        </script>

The problem is that after the ajax response it just reload the edit_profile.php page again like F5 on browser, what to do for the page do not reload?

Upvotes: 0

Views: 97

Answers (1)

mohamed hassan
mohamed hassan

Reputation: 489

Write

 $("#update_profile").click(function(e) {
 e.preventDefault(); //to prevent do action

Upvotes: 1

Related Questions