在计算AJAX POST函数时遇到问题


Having problems figuring out AJAX POST functions

我尝试使用AJAX发布,因为我不想每次点击都使用提交按钮并重新加载页面。我将此代码用于ajax:

<script language="JavaScript"><!--
function postit()
{
    var frm = $('#pmconfirm');
    $.ajax({
    type: "POST",
    url: "bitcin",
    data: frm.serialize(),
    success: function(msg){
    $("#main").hide();
    $("#main").html(msg).show();
    },
    error: function(msg){
    $("#main").html("<font color='#ff0000'>Ajax loading error, please try again.</font>").show();
    }
    });
}
setTimeout("postit()",2000);
//--></script>

接下来,我使用这个表格:

<form action="" name="fcaptcha" method="post">
<input type="hidden" id="bitcoin" name="bitcoin">
<input type="hidden" id="pmconfirm" name="pmconfirm" src="http://www.mvixusa.com/newsletter/2010/11/newsletter-membership-confirmation/images/confirm-button.png" alt="Submit Form" onclick='"document.getElementById("fcaptcha").submit()'"/>
  </form>
<div id="main">
</div>

这是有效的,但我不给我结果?

if (isset($_POST['bitcoin']))
{
 // My code here works, because it works when i dont use ajax
 // And I have some things to check like if it wasnt what i wanted 
 // it returns some message which is shown with php.
}
<div id="messaget">
<?php
if($failed == 1) echo $messages; 
?>
</div>

这是应该显示消息的部分,我尝试在发布后使用#messaget标记来显示HTML,但它不起作用,我尝试在此页面中显示整个页面,但它仍然不起作用。

网址:"bitcin",完全可以,我用了htaccess。有人能发现问题出在哪里吗?

在表单中添加一个id:

<form id="pmform" action="" name="fcaptcha" method="post">

并将Js更改为:

var frm = $('#pmform');

执行时:

............
data: frm.serialize(), //this will take the form and make an array based on the names of the form elements thus having them accessible in the PHP script
..........