tags:

views:

33

answers:

2

Hi, I have the code below, which sends the value of the textarea and either gets a fail or Successful response, for now I just check if it says "hello".

function postdata()
{
    $.ajax({
    type: "POST",
    dataType: "text",
    url: "makepost.php",
    data: "post_text=" + $("#post_text").val(),
    cache: false,
    success: function(reply_text)
    {
        if (reply_text.indexOf("Successful") >= 0)
        {
            alert("Post Made");     

        }
        else 
        {
            alert(reply_text);
        }
    }
    });
}

<textarea rows="3" cols="25" id="post_text" ></textarea><br />
    <input type="submit"  id="post_bttn" value="Post" onclick="postdata(); return false;">

I have also tested just echo'ing out the value of the textarea, and all the time it is jus blank. Although in firebug it shows that I have sent that text.

Any ideas? Thanks :)

edit : added php code

<?php

$post=$_GET['post_text'];

if ($post=="hello")
{
    echo "Successful";
    return 1;
}
else
{
    echo $post;
    return 0;

}

?>
A: 

Try $("#post_text").html() instead

Mathijs Henquet
`.val()` will return the value inside the textarea.
rahul
+3  A: 

Your AJAX is using POST, while PHP is looking for GET.

Kobi
ooh yeh! Thanks , is it safe to send this via post method, I will use hidden field for user ID / session and check this against the database before a user can post.
Elliott