Javascript 为什么我的ajax提交没有向数据库添加数据?
当我提交表单时,它不向数据库添加数据或不发送邮件。我一页有两张表格。php代码还可以。当我直接将表单提交到php页面时,它就会工作。但通过jquery代码,它并没有发送 这里是html代码Javascript 为什么我的ajax提交没有向数据库添加数据?,javascript,php,jquery,ajax,forms,Javascript,Php,Jquery,Ajax,Forms,当我提交表单时,它不向数据库添加数据或不发送邮件。我一页有两张表格。php代码还可以。当我直接将表单提交到php页面时,它就会工作。但通过jquery代码,它并没有发送 这里是html代码 <div class="notify"> <h2>Subscription Done! <span>x</span></h2> </div> <form id="formoid" action="subscribe.php"
<div class="notify">
<h2>Subscription Done! <span>x</span></h2>
</div>
<form id="formoid" action="subscribe.php" title="" method="post">
<input type="text" name="nameid" id="nameid" placeholder="Name" required ><br>
<input type="email" name="emailid" id="emailid" placeholder="Email" required ><br>
<input type="submit" id="submitButton" name="submitButton" value="Subscribe Today">
</form>
<div id="contact">
<a name="contact" style="padding-top: 100px;"></a>
<h2 class="guide">CONTACT</h2>
<form id="cont-form" method="post" action="processing.php">
<input type="text" id="name" name="name" required placeholder="Name"><br>
<input type="text" id="email" name="email" required placeholder="E-mail"><br>
<input type="text" id="subject" name="subject" required placeholder="Subject"><br>
<textarea name="comments" id="comments" rows="10" cols="30" required placeholder="Message"></textarea><br>
<input type="submit" id="submit" name="submit" value="send">
</form>
<div id="cont-notify">
<h2>Email Sent<span>x</span></h2>
</div>
</div>
这可能是一个暗示。。
jquery在此页面中工作。
jquery无法使用此页面。找不到原因..您的jQuery文件和PHP文件在同一文件夹中吗?两个表单都失败了吗?或者只是订阅表单?订阅表单中字段的名称与相关javascript不匹配。在订阅表单中,字段的名称为“nameid”和“emailid”。虽然javascript表单使用了“name”和“email”。对于类似的问题,我会在php中打印值,然后在javascript中使用console.log显示$.post响应数据。它通常会给您提示。php文件位于根文件夹中,jquery位于另一个文件夹中@普拉瓦
/*subscribe*/
/* attach a submit handler to the form */
$("#formoid").submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var $form = $( this ),
url = $form.attr( 'action' );
/* Send the data using post */
var posting = $.post( url, { email: $('#emailid').val(), name: $('#nameid').val() } );
/* Put the results in a div */
posting.done(function( data ) {
$("#formoid").fadeOut(1000);
$(".notify").fadeIn(1000);
$(".notify span").click(function(){
$(".notify").fadeOut(1000);
$("#formoid").fadeIn(1000);
});
});
});
/*contact form*/
/* attach a submit handler to the form */
$("#cont-form").submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var $form = $( this ),
url = $form.attr( 'action' );
/* Send the data using post */
var posting = $.post( url, { name: $('#name').val(), email: $('#email').val(), subject: $('#subject').val(), message: $('#comments').val() } );
/* Put the results in a div */
posting.done(function( data ) {
$("#cont-form").fadeOut(1000);
$("#cont-notify").fadeIn(1000);
$("#cont-notify span").click(function(){
$("#cont-notify").fadeOut(1000);
$("#cont-form").fadeIn(1000);
});
});
});