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
Post a Comment