gpt4 book ai didi

javascript - 弄清楚 AJAX POST 函数时遇到问题

转载 作者:行者123 更新时间:2023-11-28 19:22:27 26 4
gpt4 key购买 nike

我尝试使用 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
..........

关于javascript - 弄清楚 AJAX POST 函数时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28585787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com