jquery - Using ajax for form submission with multiple forms generated by php on page -
i have page multiple forms same thing, acting like button each post in page, , right next number of likes inside div named "likes".$id, can identify write likes count after ajax call. trying use jquery ajax function, couldn't set div write results of function.
$.ajax({ type:'post', url: 'likepost.php', data:$('#like').serialize(), success: function(response) { $('#like').find('#likediv').html(response); } }); and how access data on likepost.php? terrible javascript, hope me , explain how jquery function works, because i've been copying , pasting without knowing doing.
would work?
$(function () { $("#likebutton").click(function () { var id = $('input[name=id]'); // me trying form value $.ajax({ type: "post", url: "likepost.php", data: $("#like"+id).serialize(), // form called like+id e.g. like12 success: function(data){ $("#likes"+id).html(data); // write results e.g. <div id='likes12'> } }); }); }); i put in code when button clicked, usual post refreshing page done. why that?
making mini-form, serializing it, , posting seems lot of heavy lifting when want send id likepost.php script.
why not retrieve id , post script?
Comments
Post a Comment