[英]Page not getting redirected php
I have passed some values from a page to another using ajax with request method post. 我已经使用带有请求方法post的ajax将一些值从页面传递到了另一个页面。 But there is one condition that f some one is directly accessing the url, it should be redirected to some other page. 但是有一个条件,如果有人直接访问url,则应将其重定向到其他页面。 Problem is that its not getting redirected (In else condition in img.php) . 问题是它没有被重定向(在img.php中的其他条件下) 。 Can any one tell me what mistake I am committing? 谁能告诉我我犯了什么错误?
Thanks in advance. 提前致谢。
Code:- 码:-
imageupload.php: 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: 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");
}
See this post https://stackoverflow.com/a/21229246/682754 看到这个帖子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 在img.php中的PHP代码顶部尝试以下内容
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
Would advise removing that once you've found your issue 建议您在发现问题后将其删除
它适用于我删除Location
和之间的空格:
header("Location: ../core.php");
Error found. 发现错误。 In the core.php thre is one code which stopping the further execution of code. 在core.php中,有一个代码停止了代码的进一步执行。 Its specially coded for uid = 6. Thanks for your time. 它为uid = 6专门编码。谢谢您的时间。
Dont use header("Location : ../core.php");
不要使用header("Location : ../core.php");
some time it gives error or not working properly so use javascript redirection 一段时间会给出错误或无法正常工作,因此请使用javascript重定向
like 喜欢
?>
<script>window.location='../core.php';</script>
<?php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.