为什么我的ajax提交没有向数据库添加数据?

时间:2014-06-13 04:29:49

标签: 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" 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代码..

/*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);
    });
  });
});

这可能是一个提示.. http://ipartner.ca/idle/ jquery在此页面中工作。 http://ipartner.ca/idle/processing.php jquery无法使用此页面。找不到原因..

0 个答案:

没有答案