Send return entire HTML page

When I submit a FORM to my page, my "response text" returns the HTML of the entire page, not just the form that was submitted. This is normal?

0


a source to share


1 answer


responseText is an XHR that says "What the server will respond to the request with, excluding the HTTP headers."

It's perfectly okay for him to include a complete HTML document if you're accessing a resource dedicated to responding to regular form submissions.

It sounds like you need to be smarter about what the server is responding to.



This simple example (written in Perl, see link for more context) checks a query string parameter to decide whether to place the data received in an HTML template and return it, or convert the data to JSON and return it instead.

  if ($view eq "json") {
    my $data = $json->convert_blessed->encode($vars);
    print $q->header('application/json;charset=utf-8'), $data;
    return;
  }

  my $output;
  $tt->process('html.tt', $vars, \$output)
    || die $tt->error(), "\n";

  print $q->header('text/html;charset=utf-8'), $output;

      

+1


a source







All Articles