replacing php form with new content on submit using jquery
I have a poll with the following action
echo("\t<form class=\"vote\" method=\"post\" action=\"" . $url . "vote.php\">\r\n");
vote.php calls several validating functions and finally displays the poll results
开发者_开发百科What I want is when the submit button is pressed, using jQuery, call vote.php and display the vote result replacing the poll.
Thanks in advance.
You can use jquery to submit your data. You can find plenty of resources if you search for it. Here's one.
I would have vote.php echo the html for the poll results. You can then use JQuery to replace the content of the poll's div with the poll results using the success() function.
Something like this, probably (untested):
$('.vote').submit(function()
{
var action = $(this).attr('action');
var data = $(this).serialize();
$('#insert-here').load(action, data));
});
精彩评论