php - Ajax call after submit does not call the right action/controller in Yii -


in following jquery script, use 3 functions, create, update , save comments. when create new record, create function called , if click save, record saved. if refresh page , wants update record, works. (update save functions)

but when want update after create/save without refreshing page, function save called instead of update/save.

i need unbind events, not work me. save triggered click , inside it, submit event linked element.

i read somewhere it not practice solution read trigger submit event click function, tried reloads page want avoid because i'm using ajax.

edit

i put trace , can see when want update after create/save, call save method not go inside method, not go update method either. url called contains save update call parameters.

/blog/index.php/save...

my understanding in mvc pattern, controller method render view. since last view rendered after create/save done save action controller, submit done after call controller view rendered.

any insights appreciate.

$(document).ready(function() {      $("input.switch-input:radio").click(function(e) {              var comment = $(this).data('comment');             var val = $(this).data('val');              if (comment.length == 0){   // new record                 $.ajax(                  {                     --> call url create new record                  });             }             else if(comment !== val){                 if (confirm ("change comment?")){                      $.ajax(                      {                     --> call url update record                     });                 } else{                     alert('no');                 }             }      }) ;     $('body').on('click','#savecomment',function(e) {         e.preventdefault();         var url = $(this).val();             $("#comment-form").submit(function(e) {                 var postdata = $(this).serialize();                 $.ajax(                  {                     --> call url save data                 });                 e.preventdefault(); //stop default action                 });             $("#comment-form").submit();             $("#comment-form").unbind('submit');             $("#savecomment").unbind('click');         });  }); 

if you're using on events, method unbind them off(). however, if want event trigged once, you're better off using .one() method instead.


Comments

Popular posts from this blog

Change the color of an oval at click in Java AWT -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -