0

I'm attempting to create a post value from an on click event.

From here:

$(document).ready(function(){
    $("div").click(function(){
        var pastDATE = $(this).text();  
            alert(pastDATE);
        }); //end click
    }); //end ready

I've tried numerous variations on the following code in attempt to get the post variable to work but am obviously missing something critical.

$(document).ready(function(){
    $("div").click(function(){
        var pastDATE = $(this).text.post("CalendarFunction.php", function() {
             alert("success");
             })
            .done(function() {
                alert("second success");
                    })
            .fail(function() {
                alert("error" );
                    })
            .always(function() {
                alert("finished");
            });
         });

The error console is telling me I have an undefined object. Can someone show me how to fix this?

2
  • what are you trying to do? how are you trying to use $(this).text()? Commented Nov 13, 2014 at 16:41
  • 1
    I'm trying to pass the data pulled with $(this).text() as POST data to a php script. *edited extra words Commented Nov 13, 2014 at 16:50

1 Answer 1

2

You've gotten the pastDATE successfully now you just have to send it with your post request.

http://api.jquery.com/jquery.post/

the second param of the jquery.post is the data to be sent

var pastDATE = $(this).text()
$.post('url', pastDATE, function() {

});

What sort of data is your php script expecting? what is the key that it is expecting you might need to key your post value

var data = {
  yourKey: pastDATE
}
$.post('url', data, function() {});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.