开发者

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!


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...


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",


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


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


try

return false;

instead of

preventDefault();


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜