drw85135 2012-04-16 05:35
浏览 31

浏览器忽略来自ajax响应的标头刷新

In my javascript I have some ajax requests $.getJSON({...}) for various actions. I have a php app that handles these ajax requests. Before processing the actual request, my app first checks the session and in the case the user hasn't logged in yet, it sends a refresh signal back. Something like:

if (not logged in) {
header('Refresh: 0;');
}
else {
//process request
}

But the client doesn't actually refresh. Is there something I'm missing when it comes to AJAX requests and the http refresh header?

  • 写回答

2条回答 默认 最新

  • dsfdf854456 2012-04-16 05:39
    关注

    AJAX requests don't affect the browser until told to do so. Meaning, if i fetch a page using AJAX, it gets returned, maybe stored in a variable and that's it. It does not do anything after that. You need to parse the return data and act accordingly.

    In your case, you might rather return something like JSON, have the client side parse what the return data meant, and act accordingly.

    i tend to do something like:

    {
        "directives": {
            //contains directives what to do first before parsing the data
            "whatToDo" : "redirect" 
        },
        "payload" : {
            //actual page data
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了