Ajax returning the error from server plus the header
Hi, this probably has been posted before but after some hours of searching i couldn't find anything.
i have a form that collect data from the user and it is process using php before been inserted to the database.To process the form i created a page call upload.php. This page has a header footer and the form itself. I'm using ajax to collect the data coming from the server to let the user know the status. The problem that i'm having now if for some reason there is an error in the form, let say a blank field, php will send the error and and the ajax call catch it and post to the browser like it supposed to but not only posting the error back to the browser, it posting the header and footer on the same page. So the page end up with two headers and footers. I already had tried the follow.
- <?php
- $ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH'] ) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
- if(!$ajax){
- ?>
- <DOCTYPE HTML>
- <html>
- <head>
- <-- tittle, meta, links elements--> goes here
- </head>
- <body>
- <?php
- }// end of if
- some ajax and non ajax content
- ?>
- </body>
- </html>
I tried the obout code between element in the page and still returning the head and footer with the error. The following code are from my jQuery side.
- $('#upload.php').submit(function(event){
- var formInfo = $(this).serialize();
- $.post('upload.php',formInfo,function(data){
- $('#errors').html(data);
-
- });//end of post
-
- event.preventDefault();
- });//end of submit
I hope someone can help me with this issue. Thanks in advance.