admin管理员组文章数量:1398818
i want to redirect from page a to page profile and in between there is a post session on them. in this case let's say the data is variable $name
in string. 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:
<?php echo $_POST['result']?>
the oute should be the value from result
in which determined on page a
.
but so there is an error message saying unidentified index
. so where am i doing wrong?
i want to redirect from page a to page profile and in between there is a post session on them. in this case let's say the data is variable $name
in string. 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:
<?php echo $_POST['result']?>
the oute should be the value from result
in which determined on page a
.
but so there is an error message saying unidentified index
. so where am i doing wrong?
-
1
on which line it shows
undefined index
? – Arun Commented Oct 23, 2014 at 11:14 - How does the html look? – Albin Commented Oct 23, 2014 at 11:15
- I tried this and it works fine for me. – Albin Commented Oct 23, 2014 at 11:22
- @Albin the error occured when i call the data on page profile. it is actually an autoplete search and when i click on the name, it directs me into the profile page. the above code is the click function. – user2891092 Commented Oct 23, 2014 at 11:32
- @Arun it shows on the profile page. it seems does not recognize the $_POST['result'] data – user2891092 Commented Oct 23, 2014 at 11:32
2 Answers
Reset to default 4Could it be, that your data parameter is wrong? I have my ajax calls as folowing:
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.
You can pass it like this, then it will be in $_GET
success: function(data) {
window.location.href = "profile.php?result="+data; // replace
}
本文标签: javascriptredirect page using ajax amp jquery (php)Stack Overflow
版权声明:本文标题:javascript - redirect page using ajax & jquery (php) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744647097a2617461.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论