php - AJAX post not working -


i'm using jquery , codeigniter update database via ajax. following code not seem or send controller when button clicked...

jquery:

$("#button_submit1").click(function(e) {      $.ajax({         type: "post",         url: window.location.href,         datatype: "json",         data: $('#writereview_form').serialize() + '&ajax=true',         cache: false,         success: function(data) {                     alert("yay");                     //$("#writereview_box").fadeout(1000);         }     });      return false;  }); 

html:

<form action="http://mysite.com/places/writereview/2107" id="writereview_form" method="post" accept-charset="utf-8">     ... ...  <input type="submit" name="submit" value="submit review" class="button_submit" id="button_submit1"> 

any ideas why ajax data not being sent?

in case better bind 'submit' event on form , use preventdefault() stop html submission , use ajax instead.

you should use form's action instead of window.location

$("#writereview_form").submit(function(e) {   var $this = $(this);   e.preventdefault();    $.ajax({       type: "post",       url: $this.attr('action'),       datatype: "json",       data: $this.serialize() + '&ajax=true',       cache: false,       success: function(data) {                   alert("yay");                   //$("#writereview_box").fadeout(1000);       }   });  }); 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -