Trying to post a form with jquery and the response data is the html from the current page, not the url specified in the function.
<form name="vote_form" class="vote_form" action="vote.php">
<input type="hidden" name="sid" id开发者_开发问答="sid" value="2056" />
<input type="submit" name="up" id="up" value="Vote Up" />
<input type="submit" name="down" id="down" value="Vote Down" />
</form>
Here's the jquery
$(document).ready(function() {
$(".vote_form").submit(function() { return false; });
$("#up, #down").click(function(event) {
$form = $(this).parent("form");
$.post($form.attr("action"), $form.serialize() + "&submit="+ $(this).attr("name"), function(data) {
$('#results').html(data);
});
});
});
For reference if there is an issue here, the .htaccess
Options +ExecCGI
AddHandler php-cgi .php .html .htm .xml
Action php-cgi /cgi-bin/php.cgi
<FilesMatch "^php5?\.(ini|cgi)$">
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS
</FilesMatch>
#Options +Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
I read one question here with a similar issue fixed changing URL PROTOCOL from AUTO to URI_REQUEST but I am not using CodeIgnitor or any other framework.
I've basically stripped everything from the page and just using the form and jquery above (vote.php only prints out the $_POST variables - tried with $_REQUEST also).
Basically I'm stumped. Any thoughts?
Have you ever tried alert( $form.attr("action") )
just to be sure you are getting the right thing? And also going to vote.php with your browser?
精彩评论