开发者

Is there an error in this jquery file?

开发者 https://www.devze.com 2023-01-16 21:08 出处:网络
$(document).ready(function(){ /* fetch elements and stop form event */ var submitData = $(\"form.follow-form\").submit(function (e) {
$(document).ready(function(){    
    /* fetch elements and stop form event */
    var submitData = $("form.follow-form").submit(function (e) {
        /* stop event */
        e.preventDefault();
        /* "on request" */
        $(this).find('i').addClass('active');
        /* send ajax request */

        $.ajax({
            type: "POST",
            url: "recycle.php",
            data: submitData,
            dataType: "html",
            success: function(msg){
                if(parseInt(msg)!=0)
                {            
                    /* find and hide button, create element */
                    $(e.currentTarget)
                      .find('button').hide()
                      .after('<span class="following"><span></span>Recycled!</span>');
                }
            }    
        });
    });
});

I think there is an error in this jquery syntax and or it could be my php code, I cant seem to find it!!

this is the recycle.php

<?php session_start();
include_once ('includes/connect.php');

$id = $_POST['id'];
$tweet =$_POST['tweet'];


  mysql_query("INSERT INTO notes SET user_note='".$_POST['tweet']."',dt=NOW(),recycle_id='".$id."', user_id = '".$_SESSION['user_id']."' ");



?>

and this is the html code

<form class="follow-form" method="post" action="recycle.php">
    <input name="id" value="$id" type="hidden">
        <input name="tweet" value="$tweet" type="hidden">
    <button type="submit" value="Actions" class="btn follow" title="123456">
        <i></i><span>recyle</span开发者_运维问答>
    </button>
</form>


Your use of submitData looks strange to me. You don't have to declare that variable and it will not contain the data of the form (I think submit() returns nothing, so submitData would be undefined).
I think you have to do:

$("form.follow-form").submit(function (e) {
  //...
  $.ajax({
    type: "POST",
    url: "recycle.php",
    data: $(this).serialize(), // gets form data
    dataType: "html",
    success: function(msg){/*...*/}
  });
});

Reference: .serialize()


If you're using jQuery you probably already know this, but if you use Firebug it should show you any syntax errors. Just a thought.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号