Reputation: 100
I have passed some values from a page to another using ajax with request method post. But there is one condition that f some one is directly accessing the url, it should be redirected to some other page. Problem is that its not getting redirected (In else condition in img.php) . Can any one tell me what mistake I am committing?
Thanks in advance.
Code:-
imageupload.php:
document.getElementById("submit").addEventListener("click", function(event){
event.preventDefault();
saveImgfunc();
});
function saveImgfunc(){
var form = new FormData(document.getElementById('saveImg'));
var file = document.getElementById('imgVid').files[0];
if (file) {
form.append('imgVid', file);
}
$.ajax({
type : 'POST',
url : 'core/img.php',
data : form,
cache : false,
contentType : false,
processData : false
}).success(function(data){
document.getElementById('msg').innerHTML = data;
});
}
img.php:
<?php
require '../core.php';
$qry = new ProcessQuery('localhost', 'root', '', 'mkart');
$uid = 6;
if($_SERVER["REQUEST_METHOD"] == "POST"){
//Some code here
}
else{
header("Location : ../core.php");
}
Upvotes: 1
Views: 95
Reputation: 465
Dont use header("Location : ../core.php");
some time it gives error or not working properly so use javascript redirection
like
?>
<script>window.location='../core.php';</script>
<?php
Upvotes: 0
Reputation: 100
Error found. In the core.php thre is one code which stopping the further execution of code. Its specially coded for uid = 6. Thanks for your time.
Upvotes: 0
Reputation: 334
It works for me removing the whitespace between Location
and :
header("Location: ../core.php");
Upvotes: 1
Reputation: 5721
See this post https://stackoverflow.com/a/21229246/682754
There's a good chance that you may have some whitespace before you use the header function? Perhaps in the form of a hidden error/warning.
Try the following at the top of your PHP code in img.php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
Would advise removing that once you've found your issue
Upvotes: 3