Skip to content
Advertisement

Trailing html with ajax response form php

I am trying to send info to a php file from an html form. The form works just fine and php processes the information correctly but I am having trouble with the response from the callback.

Here is the javascript code:

JavaScript

Here is the php code:

JavaScript

}

Everything works fine except for the response from the call back. Here is what I see when I console log the data from the callback.

JavaScript

As you can see the json object is there but there are some trailing html that is causing an issue.

Advertisement

Answer

You can stop the execution of the rest of your PHP script by adding die() or exit() after the echo json_encode($return); line.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement