javascript - how can i bind function one time once i click submit button? for jquery ajax form -


i use django make website . want let people create group in website .so use html form let them fill in info , upload image group logo. want let people preview logo,so use ajax upload picture file first.i add 2 buttons in page,button1 upload picture file in ajax way,button2 post whole form server .for ajax upload picture ,i use plugin http://malsup.com/jquery/form/ ok here code

<!doctype html> <html> <head> <script src="jquery-1.10.2.min.js"></script>  <script src="jquery.form.min.js"></script>   <meta charset="utf-8"> <title>test</title> </head> <body>     <form id="test" action="/accounts/signup/" method="post"> <input type="text" id="text" name="text" /> <input type="file" name="file" id ="file" /> <a href="javascript:;" class="btn_gray_light" id="tnpicsubmit"><span >submitpicture</span></a>  <a href="javascript:;" class="btn_celadon_large signup"><span>confirm</span></a> </form>    <script language="javascript" type="text/javascript"> $("document").ready(function(){  $("#tnpicsubmit").click(function(){     $("#form").submit(function(){        var options={             url:"/article/nodetpic/",             type:"post",             datatype:"json",           };          $("#form").ajaxsubmit(options);         return false;     }).submit();  });   $(".signup").click(function(){     $("#test").submit()  }); })  </script>  </body> </html> 

this code works,but not well. because ,the first time choose 1 picture,and click button id #tnpicsubmit,yes picture uploaded host,i through every thing ok .then test 2nd time,and time ,the same picture file ,upload 2 times,i find 2 same pictures in host ,and test 3rd time ,same picture upload 3 times. know problem .i think problem ,every time click button id #tnpicsubmit,it add same function form submit event,that why every time +1 times picture uploaded.

how solve problem ?i mean,just 1 click ,upload 1 picture 1 time ajax file upload.

as understand question, try using one():

$("#form").one('submit', function(){...}); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -