$.get函数不在Chrome中运行,但在IE和FireFox中运行
$.get function not running in Chrome but working in IE and FireFox
我在一个使用phpPOST将文件上传到服务器的网站上工作,我正在尝试为上传添加进度条。我遵循了这个指南:
http://www.ultramegatech.com/2010/10/create-an-upload-progress-bar-with-php-and-jquery/
它在ie和firefox中效果很好。但是进度条从未在chrome中更新。
调用此函数时超时值为"500"。
function updateProgress(id) {
var time = new Date().getTime();
// Make a GET request to the server
// Pass our upload identifier as a parameter
// Also pass current time to prevent caching
$.get('progressbar.php', { uid: id, t: time }, function (data) {
// Get the output as an integer
var progress = parseInt(data, 10);
if (progress < 100 || !started) {
var div = document.getElementById('statusfield');
div.innerHTML = progress + '%';
// Determine if upload has started
started = progress < 100;
// If we aren't done or started, update again
updateProgress(id);
}
if (progress > 99) {
var div = document.getElementById('statusfield');
div.innerHTML = 'Komprimerar fil...';
}
// Update the progress bar percentage
// But only if we have started
started && pbar.progressbar('value', progress);
});
}
此函数调用.php文件"progressbar.php",该文件将上传进度以百分比形式返回。
progressbar.php:
<?php
if (isset($_GET['uid'])) {
// Fetch the upload progress data
$status = uploadprogress_get_info($_GET['uid']);
if ($status) {
// Calculate the current percentage
echo round($status['bytes_uploaded']/$status['bytes_total']*100);
}
else {
// If there is no data, assume it's done
echo 100;
}
}
?>
我已经在chrome中测试了代码,并调用了函数"updateProgress"。但它从未通过:
$.get('progressbar.php', { uid: id, t: time }, function
有人知道可能出了什么问题吗?
谢谢!
在chrome中,转到开发工具(选项->工具->开发工具)并查看网络面板。一旦调用$.get方法,您将看到您的请求和结果-您可以看到它是否失败(例如,如果发生404),因此chrome可能没有按应有的方式设置地址,或者发送的数据/返回的数据是否不正常。
相关文章:
- JavaScript获胜't运行,但在jsFiddle中工作
- jQuery自动完成在Firefox中运行良好,但在Chrome中则不然
- 变量在运行时未定义,但在使用调试器时定义
- Ajax调用在InternetExplorer中冻结UI,但在firefox中运行良好
- 以下颜色更改功能在IE9和Firefox中运行良好,但在早期的IE或Chrome中则不然
- Javascript'元素'在ie中未定义,但在chrome和firefox中运行良好
- jQuery插件在本地主机上运行良好,但在web服务器上却与bg镜像混淆
- Jquery在生产和Heroku中不起作用,但在开发中运行良好
- 这个jQuery代码在Mozilla上运行良好,但在Chrome,Opera,Safari上则不然
- 引导工具提示在实时站点上不起作用,但在控制台上运行良好
- 漂亮的照片在Dreamweaver上完美运行;但不能在任何浏览器上在线工作
- 离子应用程序在浏览器上运行,但在我的安卓设备中无法正常工作
- Javascript键码在Firefox中不起作用,但在chrome中运行良好
- jQuery成功处理程序未在生产服务器上执行,但在dev中运行良好
- Jquery.hide()和.show()在firefox上运行速度较慢,但在chrome上运行良好
- 对象在循环中运行时未定义,但在按顺序执行时未定义
- 为什么代码在jsfiddle上运行良好,但在我的dreamweaver上却不正常
- D3图表在jsfiddle上运行良好,但在localhost上则不然
- Javascript无法在Chrome中运行??但在FF和IE中有效
- 是否有“仅在鼠标结束时运行但在鼠标未结束时停止”的 javascript 命令