Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 会话过期后,我的ajax调用返回未找到文件错误?_Jquery_Ajax_Coldfusion_Http Status Code 401_Jqxhr - Fatal编程技术网

Jquery 会话过期后,我的ajax调用返回未找到文件错误?

Jquery 会话过期后,我的ajax调用返回未找到文件错误?,jquery,ajax,coldfusion,http-status-code-401,jqxhr,Jquery,Ajax,Coldfusion,Http Status Code 401,Jqxhr,我已经为单页应用程序创建了登录系统。登录过程的第一步是用户身份验证。一旦用户登录,他们的会话将启动。我已经在服务器端设置了30分钟的会话时间。在客户端,我使用JavaScript跟踪何时显示有关会话时间的警告模式框。不过,只要计算机未处于睡眠模式或移动设备未锁定,此功能就可以正常工作。我使用了另一种方法来跟踪这些活动,方法是在JavaScript中设置每秒运行的时间间隔,检查用户上次活动的时间差,并与当前时间进行比较。若差异大于30分钟,我会向他们显示返回登录页面的链接。在我打开android手

我已经为单页应用程序创建了登录系统。登录过程的第一步是用户身份验证。一旦用户登录,他们的会话将启动。我已经在服务器端设置了30分钟的会话时间。在客户端,我使用JavaScript跟踪何时显示有关会话时间的警告模式框。不过,只要计算机未处于睡眠模式或移动设备未锁定,此功能就可以正常工作。我使用了另一种方法来跟踪这些活动,方法是在JavaScript中设置每秒运行的时间间隔,检查用户上次活动的时间差,并与当前时间进行比较。若差异大于30分钟,我会向他们显示返回登录页面的链接。在我打开android手机的浏览器并登录之前,一切正常。之后,我在手机上打开了一些其他应用程序并锁定手机,30分钟后回来,我没有看到我的JavaScript被触发以显示与登录页面的用户链接。相反,我在同一个页面上,例如,如果我单击
Submit
按钮发送ajax调用,我会收到错误:
File not found Components/Login.cfm

下面是我使用JQuery/Ajax和ColdFusion的登录代码示例:

ColdFusion组件文件:

<cfcomponent output="false">

    <cfset this.name = "jqlogin">

    <cfset this.sessionManagement = true>

    <!--- Run before the request is processed --->
    <cffunction name="onRequestStart" returnType="boolean" output="false">
        <cfargument name="thePage" type="string" required="true">
        <cfset var page = listLast(arguments.thePage,"/")>

        <cfif not listFindNoCase("Login.cfm,Auth.cfc",page)>      
            <cfif not structKeyExists(session, "loggedin") or session.loggedin is false>
                <cflocation url="Login.cfm" addToken="false">
            </cfif>
        </cfif>
        <cfreturn true>
    </cffunction>

    <!--- Runs when your session starts --->
    <cffunction name="onSessionStart" returnType="void" output="false">
        <cfset session.loggedin = false>
    </cffunction>
</cfcomponent>

我认为问题在于,一旦服务器会话超时,对任何其他文件的访问都会受到限制,但是
Login.cfm
Auth.cfc
。因此,如果我尝试提交表单,JQuery Ajax调用将在Components文件夹中查找
Login.cfm
。我想知道如果
url:Components/AjaxFunction.cfc
不存在,我怎么能让用户返回到
Login.cfm
?我还想提到,一旦会话超时,系统中的任何ajax调用都会发生这种情况。屏幕上显示警告消息
Error:notfound
,如果我检查dev tools ajax响应,就会看到
file Not found Components/Login.cfm
。如果有人知道这种情况的最佳解决方案,请告诉我。谢谢。

将jQuery上的失败更改为重定向到登录页面

 }).fail(function(jqXHR, textStatus, errorThrown){
        // This is like an HTTP redirect.
        window.location.replace("http(s)://[yourURL]/Login.cfm");  
        //alert("Error: "+errorThrown);
        // Log to console or something if you need to see the error.
    });

我想知道浏览器上是否发生了重定向。如果您使用绝对路径,是否可以对cfc进行罚款?@JamesAMohler如果我尝试访问AjaxFunctions.cfc,则会话超时后,我会收到上面提到的错误消息。我认为cfc内部的
是导致问题的原因。你确定你不想这样吗?@JamesAMohler你可能是对的。我必须测试一下。也许我可以用我的应用程序的完整路径URL替换Login.cfm?让您的ajax返回状态码或其他信息。然后让jQuery/Ajax执行重定向。
 }).fail(function(jqXHR, textStatus, errorThrown){
        // This is like an HTTP redirect.
        window.location.replace("http(s)://[yourURL]/Login.cfm");  
        //alert("Error: "+errorThrown);
        // Log to console or something if you need to see the error.
    });