dongqi8030 2018-04-16 15:58
浏览 235
已采纳

有没有办法使用ajax重定向到新页面,响应也发送到新页面

I want to redirect to a new page after the ajax is complete/success. That is working fine. But I want to view the response in the new page where I am directing to.

I am not sure if there is any existing way to do it.

function directtoedit(object) {

    $('#edit-field-tei-document-und-0-xml').focus();
    $('#toolbar-back').show();

    clickedTitle = object;

    $.ajax({
        url: "tabs/get_old_contents.php",
        data: {
            seltitle: clickedTitle
        },
        type: 'post',
        complete: function(response) {
            location.href = "tabs/test.php"
            console.log('selectHey' + response.responseText); //Want to view response in test.php
        }
    });
}
  • 写回答

1条回答 默认 最新

  • dongzhuo3202 2018-04-16 16:00
    关注

    You can save the response to local storage and retrieve after redirecting.

    complete: function(response){
        localStorage.setItem('someName', response);
        //...
    }
    

    Retrieve the response string from storage after redirecting on page 2:

    var response = localStorage.getItem('someName');
    

    Browser compatibility for localStorage

    Alternatively you can use document.cookie.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿