0

I've been searching for a while for a solution to this problem. I've found many people with the same problem, but not the same solution.

The issue I'm having is that PHP is not returning any data to the AJAX function. The alert spits out data = undefined. As you can see, using return instead of echo is not the problem. I know that the PHP script I call completes correctly because the values are properly inserted into the database. No matter where I place the echo statement, I can't get it to return the value. Am I using the data variable incorrectly? Is returnValue not the proper variable to use? Has any of the functionality I've been trying to use been deprecated? I'm really at a complete loss. I can't see why this is failing.

//AJAX function

$("document").ready(function(){

        $("#add_interest_form").submit(function(event) {
            event.preventDefault();
            $("#output").html("");

            var values = $(this).serialize();

            $.ajax
            ({
                url: "./php/add_interest.php",
                type: "POST",
                data: values,
                success: function(data) {
                    alert('data = ' + data.returnValue);
                    $("#output").html(data.returnValue);
                },
                error: function() {
                    alert('failed adding to database.  Please try again or contact the Webmaster.');
                }
            });
        });
    });

//PHP snippet echo 'Success!';

3
  • What do you get if you just alert data instead of data.returnValue? Commented Mar 15, 2014 at 20:38
  • contents of add_interest.php? Commented Mar 15, 2014 at 20:39
  • 1
    And please change $("document") to $(document) as document is not a DOM Element. Commented Mar 15, 2014 at 20:40

1 Answer 1

1

Just do alert('data = ' + data); instead of alert('data = ' + data.returnValue);.

Sign up to request clarification or add additional context in comments.

1 Comment

Finally! That worked. Fastest correct answer I've ever gotten on SO. So fast that SO won't let me accept your answer for another 5 minutes.

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.