Sandro Antonucci
Sandro Antonucci

Reputation: 1753

jquery , return false on submit doesnt work

guys I'm getting crazy I don't understand why this doesn't work (it always did!)

        //add new folder
        $("#add_folder_form").submit(function(event){

            var folder_name = $(this).find([name="folder_name"]).val();
            var post_string = "folder_name="+folder_name+"&path="+path;
            $.ajax({
                type : "POST",
                url: "/admin/controllers/add_new_folder,php",
                data : post_string,
                success: function(response){

                    if (response){
                        event.preventDefault();
                     }
                     else {
                        event.preventDefault();
                     }
                }
            })


event.preventDefault();
        });

HTML

<form  id="add_folder_form" action="" method="post">
  New folder  <input style="width: 400px" name="folder_name" type="text" />
  <input type="submit" id="add_folder_form_send" value="save"/>
</form>

I also tried to use click on #add_folder_form_send and using return false; at the bottom of the function. It always submits!

Upvotes: 0

Views: 986

Answers (6)

Emre ALPARSLAN
Emre ALPARSLAN

Reputation: 1

return function(event){event.preventDefault();}/*return false*/

Upvotes: -1

Shef
Shef

Reputation: 45589

Maybe because of this:

/admin/controllers/add_new_folder,php

... replace the comma with a dot, which will give you this:

/admin/controllers/add_new_folder.php

Upvotes: 1

calumbrodie
calumbrodie

Reputation: 4792

Is you javascript throwing any errors (check the console - set it to break on errors)?

This line looks pretty suspect (comma instead of dot)

url: "/admin/controllers/add_new_folder,php",

Upvotes: 2

K6t
K6t

Reputation: 1845

u add ',' change to '.' in folowing text add_new_folder,php add_new_folder.php

Upvotes: 1

genesis
genesis

Reputation: 50976

try

return false;

instead of

preventDefault();

Upvotes: 0

Val
Val

Reputation: 17522

Try this...

$('selector').submit(function(event){
   event.preventDefault();
   ....// your ajax code here...
   return false;
})

because by the time you hit the preventDefault(); the page has already reloaded for you ... and it's too late to carry on any scripting actions...

Upvotes: 2

Related Questions