【发布时间】:2015-05-12 10:53:06
【问题描述】:
我已经使用 ajax 和请求方法 post 将一些值从一个页面传递到另一个页面。但是有一个条件,如果有人直接访问该 url,它应该被重定向到其他页面。问题是它没有被重定向 (In else condition in img.php) 。谁能告诉我我犯了什么错误?
提前致谢。
代码:-
图片上传.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");
}
【问题讨论】:
-
var_dump($_SERVER["REQUEST_METHOD"]);exit;在if之前,看看你得到了什么。 -
当来自 iageupload.php 时,它的给定 - string(4) "POST"。在直接访问 url 时它的 lank。 @sgtBOSE
-
注意到一点:它甚至在 else 循环中。