简体   繁体   English

Chrome加载旧版本的Javascript文件

[英]Chrome Loading an Old Version of Javascript File

I am building a web application using CodeIgniter. 我正在使用CodeIgniter构建一个Web应用程序。

The problem that I'm having is that chrome is loading an older version of my javascript file main.js 我遇到的问题是chrome正在加载我的javascript文件main.js的旧版本

My Code: 我的代码:

$(document).load(function(){

/******************************************
*                                         *
*              AJAX FUNCTIONS             *
*                                         *
******************************************/    

function deactivate_dept_member(user_id, token_name, token_hash, callback)
{
    $.post(
        site_url('/ajax/deactivate_dept_member'),
        {
            'user_id':usr_id,
            token_name:token_hash
        },

        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}

function activate_dept_member(usr_id, token_name, token_hash, callback)
{
    $.post(
        site_url('/ajax/activate_dept_member'),
        {
            'user_id':usr_id,
            token_name:token_hash
        },

        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}

function get_dept_users_for_session(dept_id, token_name, token_hash, callback)
{
    $.post(
        site_url('ajax/get_dept_users_for_session'),
        {
            "dept_id":dept_id,
            token_name:token_hash

        },

        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );

}

function invite_dept_user(email_address, first_name, last_name, admin, token_name, token_hash, callback)
{
    $.post(
        site_url('ajax/invite_dept_user'),
        {
            "email_address":email_address,
            "first_name":first_name,
            "last_name":last_name,
            "admin":admin,
            token_name:token_hash
        },
        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}

function get_department_members(dept_id, token_name, token_hash, callback)
{
    $.post(
        site_url('ajax/det_department_members'),
        {
            "dept_id":dept_id,
            token_name:token_hash
        },
        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}




/******************************************
*                                         *
*              UTILITY FUNCTIONS          *
*                                         *
******************************************/
function site_url(add_on)
{
    return 'http://localhost:8080/app/index.php'+add_on;
}

function getUserTypeString(user_status)
{
    switch(user_status)
    {
        case "1":
            return "Invited";
        case "2":
            return "Active";
        case "3":
            return "Inactive";
        default:
            return "";
    }
}


function isDepartmentAdmin(user_role)
{
    if(user_role == 2){
        return true;
    }
    return false;
}

function get_error_message(error_code)
{
    switch(error_code)
    {
        case "20130":
            return 'The username already exists';
        default:
            return 'A general error occured';
    }
}


})

What Chrome Says Is My Source: Chrome表示我的来源:

/******************************************
*                                         *
*              AJAX FUNCTIONS             *
*                                         *
******************************************/    

function deactivate_dept_member(user_id, token_name, token_hash, callback)
{
    $.post(
        site_url('/ajax/deactivate_dept_member'),
        {
            'user_id':usr_id,
            token_name:token_hash
        },

        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}

function activate_dept_member(usr_id, token_name, token_hash, callback)
{
    $.post(
        site_url('/ajax/activate_dept_member'),
        {
            'user_id':usr_id,
            token_name:token_hash
        },

        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}

function get_dept_users_for_session(dept_id, token_name, token_hash, callback)
{
    $.post(
        site_url('ajax/get_dept_users_for_session'),
        {
            "dept_id":dept_id,
            token_name:token_hash

        },

        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );

}

public function invite_dept_user(email_address, first_name, last_name, admin, token_name, token_hash, callback)
{
    $.post(
        site_url('ajax/invite_dept_user'),
        {
            "email_address":email_address,
            "first_name":first_name,
            "last_name":last_name,
            "admin":admin,
            token_name:token_hash
        },
        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}

public function get_department_members(dept_id, token_name, token_hash, callback)
{
    $.post(
        site_url('ajax/det_department_members'),
        {
            "dept_id":dept_id,
            token_name:token_hash
        },
        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}




/******************************************
*                                         *
*              UTILITY FUNCTIONS          *
*                                         *
******************************************/
function site_url(add_on)
{
    return 'http://localhost:8080/app/index.php'+add_on;
}

function getUserTypeString(user_status)
{
    switch(user_status)
    {
        case "1":
            return "Invited";
        case "2":
            return "Active";
        case "3":
            return "Inactive";
        default:
            return "";
    }
}

function isDepartmentAdmin(user_role)
{
    if(user_role == 2){
        return true;
    }
    return false;
}

function get_error_message(error_code)
{
    switch(error_code)
    {
        case "20130":
            return 'The username already exists';
        default:
            return 'A general error occured';
    }
}


 �����������������

Things I've Done To Try and Fix the Problem 我已经完成的事情并解决问题

  • Disabled Cache using Chrome Developer Tools 使用Chrome开发者工具禁用缓存
  • Using the LiveReload Extension/App 使用LiveReload扩展/应用程序
  • Restarted Apache 重启Apache
  • Verified that the sharing for Vagrant is working correctly (The file is the same in the virtual centos instance I have running as it is on my Mac) 验证Vagrant的共享是否正常工作(该文件在我运行的虚拟centos实例中是相同的,因为它在我的Mac上)
  • Tried to get chrome to load a different version of the file (adding a ?2 to the end of the url to the file: localhost:8080/app/assets/js/main.js?2) 试图让chrome加载不同版本的文件(在文件的url末尾添加一个?2:localhost:8080 / app / assets / js / main.js?2)

Other Things to Note: 其他注意事项:

  • This also happens in Firefox and Safari so the problem may lie with Apache but I can't test this theory because I can't get the oci8 extension for php to compile for any other OS. 这也发生在Firefox和Safari中,所以问题可能在于Apache,但我无法测试这个理论,因为我无法获得php的oci8扩展来编译任何其他操作系统。

Edit: 编辑:

More things I've tried 我尝试过的更多东西

  • renaming file ( will work for a little bit but the problem starts happening again.) 重命名文件(稍微会有效,但问题会再次发生。)

If it works upon rename, and then stops working , then it can not be a cache of any kind (except maybe "a seriously broken one") nor a file modifying thing (eg BOM, rogue CR's, etc.). 如果它在重命名时起作用,然后停止工作 ,那么它不能是任何类型的缓存(除了可能是“严重破坏的”),也不能是文件修改的东西(例如BOM,流氓CR等)。

But I'm guessing that the file works, and then it stops working not "after a while" but "after you save it again making what seems to be a very minor and unrelated change". 但我猜这个文件是有效的,然后它停止工作而不是“一段时间后”,而是“在你再次保存它之后再做一个非常小的和无关的改变”。

If this is the case you're probably dealing with rogue CR's or weird EOF handling: try checking the file on disk with a different editor (a hex editor ideally), and/or opening it with the simplest text editor you have. 如果是这种情况,您可能正在处理流氓CR或奇怪的EOF处理:尝试使用不同的编辑器(理想情况下为十六进制编辑器)检查磁盘上的文件,和/或使用您拥有的最简单的文本编辑器打开它。

If you have a bare CR as the last character of the file, some editors and platforms will add two "strange characters" (actually another LF and another rogue CR) every time you read/write the file again. 如果你有一个裸CR作为文件的最后一个字符,那么每次你再次读/写文件时,一些编辑器和平台将添加两个“奇怪的字符”(实际上是另一个LF和另一个流氓CR)。 And those same editors won't show you those characters, so you won't be able to delete them from those editors. 那些相同的编辑器不会向您显示这些字符,因此您将无法从这些编辑器中删除它们。

UPDATE : Another distinct possibility is that you have a "hidden" UTF-8 character (or fragment thereof) which is not correctly detected. 更新 :另一个明显的可能性是你有一个“隐藏的”UTF-8字符(或其片段)未被正确检测到。 Then something very like this happens: 然后会发生类似这样的事情:

Visual Studio 2008 project file does not load because of an unexpected encoding change 由于意外的编码更改,无法加载Visual Studio 2008项目文件

...and notice that the strange characters you are getting are exactly the UTF8 signification for encoding error , which also would explain why Chrome detects an unexpected end of input . ...并注意到您获得的奇怪字符正是 编码错误的UTF8表示,这也解释了为什么Chrome检测到意外的输入结束

Try blindly selecting from the last few lines of code to the end of the file and delete the selection, then write it back: 尝试盲目地从最后几行代码中选择到文件末尾并删除选择,然后将其写回:

            return 'A general error occurred';
        }
    }
})
/* END OF FILE */

and save. 并保存。 This ought to clear things. 应该是清楚的事情。 Check with the hex editor from 'occurred' onwards if any strange characters are present. 如果存在任何奇怪的字符,请从“发生”开始检查十六进制编辑器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM