views:

52

answers:

2
$(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>
A: 

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.

Jaco Pretorius
This should be a comment.
Marko
Well I don't think there are any syntax errors, so it's probably a case of an object being null?
Jaco Pretorius
+1  A: 

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()

Felix Kling
cheers @felix, :))
getaway
@felix, can i ask why the data is not going into the database, in my recycle.php, i checked firebug and the data is being posted, can i show my php script!! is thats alright with you
getaway
@getaway: You can edit your question and add the PHP code, sure.
Felix Kling
@felix i have added the php and html code, i hope you can help me, this is a big thing for me, cheers in advance
getaway
@getaway: It could be that `recycle_id='".$id."'` has to be `recycle_id=".$id."` if `recycle_id` is defined as number. Try to run the exact statement in e.g. phpmyadmin and see if it gives you any errors.
Felix Kling
hahaha, im so stupid, i should get killed, i mispelled the recycle_id it was recyle_id in the database!! :)) thanks @felix GENIUS
getaway
@getway: Good that we worked it out :)
Felix Kling