从Ajax响应浏览器忽略头刷新 [英] browser ignoring header refresh from ajax response

查看:155
本文介绍了从Ajax响应浏览器忽略头刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的JavaScript,我有一些Ajax请求 $。的getJSON({...})的各种动作。我有一个PHP应用程序,这些处理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
}

但客户实际上并不刷新。是否有什么我失踪,当涉及到AJAX请求和HTTP刷新头?

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

推荐答案

AJAX请求不影响浏览器直到被告知这样做。意思是,如果我取使用AJAX页面,它就会被退回,也许存储在一个变量,就是这样。它没有这样做之后的事情。你需要解析返回数据,并采取相应的行动。

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.

在你的情况,你可能宁愿返回类似JSON,有客户端解析哪些返回数据的意思,并采取相应的行动。

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
    }
}

这篇关于从Ajax响应浏览器忽略头刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆