[英]redirect page using ajax & jquery (php)
i want to redirect from page a to page profile and in between there is a post session on them. 我想从页面A重定向到页面配置文件,并且在它们之间有一个发布会话。 in this case let's say the data is variable
$name
in string. 在这种情况下,我们假设数据是字符串中的变量
$name
。 so far my code is like this on page a 到目前为止,我的代码在第
jQuery("#result").on("click",function(e){
var $clicked = $(e.target);
var $name = $clicked.find('.name').html();
var decoded = $("<div/>").html($name).text();
$('#searchid').val(decoded);
//the ajax script
$.ajax({
type: 'POST',
url: 'b.php',
data: 'result='+$name,
success: function() {
window.location.href = "profile.php"; // replace
}
});
});
and on page b
the code is: 在
page b
,代码为:
<?php echo $_POST['result']?>
the outcome should be the value from result
in which determined on page a
. 结果应该是
page a
中确定的result
值。 but so there is an error message saying unidentified index
. 但因此出现一条错误消息,指出
unidentified index
。 so where am i doing wrong? 所以我在哪里做错了?
Could it be, that your data parameter is wrong? 可能是您的数据参数错误? I have my ajax calls as folowing:
我的ajax电话如下:
jQuery.ajax({
type: "POST",
url: "b.php",
data: {
result: $name
},
success: function() {
window.location.href = "profile.php"; // replace
}
});
It is a new request after the redirect. 这是重定向后的新请求。 In order to access the result you need to sotre it in som kind of session or pass it again.
为了获得结果,您需要将其以som会话的形式保存或再次传递。
You can pass it like this, then it will be in $_GET 您可以像这样传递它,然后它将在$ _GET中
success: function(data) {
window.location.href = "profile.php?result="+data; // replace
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.