0

I have the following form in my HTML page:

        <form id="submission" action="testresponse.php" method="post">
            <input id="URL" name="URL" type="text">
            <button name="Submit" type="submit">Submit</button>
        </form>

testresponse.php just contains <?php print_r($_POST); ?> to print all the post variables.

I am trying to submit the form and have it return the values on the same page that the page was submitted (i.e. return the POST variables somewhere above the form)

I used the following jQuery code:

$( document ).ready(function() {
    var frm = $('#submission');
    frm.submit(function (ev) {
        $.ajax({
            type: frm.attr('method'),
            url: frm.attr('action'),
            data: frm.serialize(),
            success: function (data) {
                console.log(data.responseText);
            }
        });
        ev.preventDefault();
    });
});

But for some reason data.responseText always returns blank

Is there a way to have my form send a POST request to a PHP page and return the result?

2
  • simply do with console.log(data) Commented Dec 8, 2016 at 7:55
  • @DaveChen type: frm.attr('method'), is right syntax Commented Dec 8, 2016 at 8:00

1 Answer 1

3

Change from

console.log(data.responseText)

to

console.log(data)
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.