chromium禁用ajax,当页面加载时,jQuery AJAX不会在Chrome/Chromium中触发

场景:我拥有的是使用nginx uploadProgress模块​​报告上载进度的上载表单。下面的代码在Firefox中工作正常,但使用Chrome和Chromium时,AJAX在页面加载时不会被触发,只会在停止请求时运行(上传到中途)。我失去了为什么它不工作。所以,任何帮助非常感谢。当页面加载时,jQuery AJAX不会在Chrome/Chromium中触发

我还发现奇怪的是,Chrome/Chromium似乎更新窗口状态栏与上传进度没有我告诉它。

HUqgd.png

有没有在那里我可以看到我设置的是。 Chrome有没有内部进度计?

upload.js

$(document).ready(function()

{

$('form').uploadProgress(

{

uploading: function(upload)

{

$('#percents').html(upload.percents+'%');

$('#progressbar').css({width: upload.percents+'%'});

},

progressUrl: "/progress",

interval: 3

});

})

jquery.uploadProgress.js

/*

* jquery.uploadProgress

*

* Copyright (c) 2008 Piotr Sarnacki (drogomir.com)

* - Original release.

*

* Copyright (c) 2011 Mathew Davies ([email protected])

* - Refactored a lot of code into their own functions

*

* Licensed under the MIT license:

* http://www.opensource.org/licenses/mit-license.php

*

*/

(function($)

{

/**

* Generate a UUID used to uniquely identify form uploads.

*

* @return string

*/

function generate_uuid()

{

var uuid = "";

for (i = 0; i < 32; i++)

{

uuid += Math.floor(Math.random() * 16).toString(16);

}

return uuid;

}

/**

* Calls the progress URL to get the latest statistics from

* the uploaded form.

*

* @return void

*/

function update(object, options)

{

$.ajax(

{

type: 'GET',

cache: false,

dataType: options.dataType,

url: options.progressUrl,

beforeSend: function(xhr)

{

xhr.setRequestHeader("X-Progress-ID", options.uuid);

},

success: function(upload)

{

alert('progress ...');

if (upload)

{

if (upload.state == 'uploading')

{

upload.percents = Math.floor((upload.received/upload.size) * 1024)/10;

options.uploading(upload);

}

if (upload.state == 'done' || upload.state == 'error')

{

window.clearTimeout(options.timer);

}

if (upload.state == 'done')

{

upload.percents = 100;

options.done(upload);

}

if (upload.state == 'error')

{

upload.percents = 0;

options.error(upload);

}

}

}

});

}

/**

* Updates the form action to use the UUID.

*/

function update_form_action(form, uuid)

{

if(old_id = /X-Progress-ID=([^&]+)/.exec(form.attr("action")))

{

var action = form.attr("action").replace(old_id[1], uuid);

}

else

{

var action = form.attr("action") + "?X-Progress-ID=" + uuid;

}

form.attr("action", action);

}

$.fn.uploadProgress = function(options)

{

var options = $.extend(

{

dataType: "json",

interval: 2000,

progressUrl: "/progress",

start: function() {},

uploading: function() {},

done: function() {},

error: function() {},

timer: ""

}, options);

return this.each(function()

{

$(this).submit(function()

{

var $this = $(this);

// Generate a new UUID

options.uuid = generate_uuid();

// Update form action with ID

update_form_action($this, options.uuid);

// Start callback

options.start();

// Start process

options.timer = window.setInterval(function()

{

update($this, options)

},

options.interval * 1000);

});

});

};

})(jQuery);

+0

Chrome确实有一个内部的进度计。它会自动显示window.status的位置,并在文件上传过程中进行更新。 –

2011-06-02 15:51:43

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值