[英]jQuery AJAX post, redirect and THEN prepend
我正在将数据发布到php文件,该文件返回一条消息。 然后,我想重定向到新页面,并在新页面顶部显示消息。
我在想这样的事情,除了我想在重定向之后添加前缀。
$.post('process.php', {"data": data}, function( message ){
window.location.pathname = '/';
$( '#content' ).prepend( message );
});
您可以使用JavaScript localStorage API保存消息并显示到页面。
$.post('process.php', {"data": data}, function( message ){
localStorage.setItem('message', message); //Store the message
window.location.pathname = '/';
});
然后在进行重定向的下一页上:
<script>
$(document).ready(function() {
$('#content').prepend(localStorage.getItem('message')); //Display the content if null, nothing will be insert to DOM
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.