Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
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:

function jvsSubmit(fd){
var submitUrl = 'repeater_field_capture.php';

$.ajax({
    type:'post',
    url: submitUrl,
    data: fd,
    contentType: false,
    processData: false,
    success: function(response){ submit_settings_form_callback(response); },
});
}
function submit_settings_form_callback(data){



console.log(data);
}

Here is the php code:

if(isset($_POST['formInfo']))
{
update_option('text',$_POST['text']);

$return = ['success' => 1, 'message' => 'Message Sent'];

echo json_encode($return);

}

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.

{"success":1,"message":"Message Sent"}<!doctype html>
<html lang="en-US" >
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Page not found &#8211; DB Website Projects</title>
<meta name='robots' content='max-image-preview:large' />
<link rel='dns-prefetch' href='//s.w.org' />
<link rel="alternate" type="application/rss+xml" title="DB Website Projects &raquo; 
Feed" href="https://projects.db-websites.com/feed/" />
<link rel="alternate" type="application/rss+xml" title="DB Website Projects &raquo; 
Comments Feed" href="https://projects.db-websites.com/comments/feed/" />
    <script>
        window._wpemojiSettings =........

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!