-1

When i try to ajax post, the second page containing header which causes the page to get status code '0'.

Now, i have to load google page in index in some section or any div. Our target is to get the header loaded file too.

index page:

<!DOCTYPE html>
<html>
<head>

</head>
<body>
<p class="result">Click me too!</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$.ajax({
    type: 'POST',
    url: 'sub2.php',
    cache: false,
    dataType: "html",
    success: function(data){
        alert(data);
$(".result").load("sub2.php");
    },
error: function(jqXHR, textStatus, errorThrown) {
    alert("status:"+jqXHR.status);
    alert("text:"+textStatus);
    alert("thrown:"+errorThrown);
    $(".result").load("sub2.php");
},
});
</script>
</body>
</html>

sub2.php page;

<?php

echo "hello";
header("location:https://google.com");

?>
Venkatesh S
  • 71
  • 1
  • 1
  • 5

1 Answers1

0

This cannot work :

<?php

echo "hello";
header("location:https://google.com");

?>

In the manual :

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

Sly
  • 361
  • 2
  • 9