I'm importing 4000 rows from a CSV file. Page 1 shows CSV file on server with PROCESS button. Onclick button, I use JQuery Ajax to call the necessary PHP code that does the import. After doing the relevant checks, updating records and inserting records etc, the whole import process takes approx 30 seconds to 1 min.

我正在从CSV文件导入4000行。第1页显示服务器上的CSV文件,带有PROCESS按钮。在Onclick按钮上,我使用JQuery Ajax来调用导入的必要PHP代码。在进行相关检查,更新记录和插入记录等之后,整个导入过程大约需要30秒到1分钟。

What I'm trying to do is display progress of this import while its processing the php code. ie:

我正在尝试做的是在处理php代码时显示此导入的进度。即:

Total records to import: 4000
Total users imported: 20 [div id=usersImported - this number dynamically increments while importing]
Total users updated: 30 [div id=usersUpdated - same here re incrementing]
Etc..

I'm not sure what the correct question is, because I've tried updating the DIVs (usersImported and usersUpdated) from the php code - couldn't get this to work. This just returns my script code to the browser but doesnt actually execute it

我不确定正确的问题是什么,因为我已经尝试从PHP代码更新DIV(usersImported和usersUpdated) - 无法使其正常工作。这只是将我的脚本代码返回给浏览器,但实际上并没有执行它

I've also tried doing an echo in the php after its either updated or inserted.. ie: usersImported1 then usersImported2 then usersImported3.. then in my JQuery success I'm trying:

我已经尝试在更新或插入之后在php中做回声..即:usersImported1然后usersImported2然后usersImported3 ..然后在我的JQuery成功我正在尝试:

if( txt.match( "usersImported" ).length > 0 ) { .. with update div innerHTML code with leading number..

if(txt.match(“usersImported”)。length> 0){.. with update div innerHTML code with leading number ..

This doesn't work because the php is not flushing as it processes, even though I've tried ob_flush(); and flush(); Or is it because the success only runs in ajax once the whole php code is complete? Is there a JQuery while: command?

这不起作用,因为php在处理时没有刷新,即使我已经尝试过ob_flush();和flush();或者是因为一旦整个PHP代码完成,成功只在ajax中运行?有没有JQuery while:命令?

So the real question I guess, is: what is the correct way to do this? From PHP update the DIVs or from $ajax update div based on PHP echos? This is similar to a progress bar update, except I want to update certain div's based on what happens during process time.

所以我想的真正问题是:这样做的正确方法是什么?从PHP更新DIV或基于PHP回声的$ ajax更新div?这类似于进度条更新,除了我想根据处理时间内发生的事情更新某些div。

I would appreciate a basic example or a link to a working sample.

我将很感激一个基本的例子或工作样本的链接。

2 个解决方案

#1


0

Guess the ajax doesn't fire since you don't close the http, it sits and wait for more to come.

猜猜ajax不会触发,因为你没有关闭http,它坐着等待更多的来。

You need streams or chunk up your work at server.

您需要流或在服务器上填充您的工作。

A dirty fix would be to let the updater write percentage to a static public file, read by the client and just keep polling that file. (add an randomized querystring so you get pass caches).

一个脏修复方法是让updater将百分比写入静态公共文件,由客户端读取并继续轮询该文件。 (添加一个随机的查询字符串,以便获得传递缓存)。

更多相关文章

  1. jquery 生成table表格 部分代码
  2. 使用jquery的$ .ajax来获取node.js脚本的输出,而不是它的代码
  3. Server.Htmlencode用于文本域显示带的html代码
  4. IOS学习之WebView加载本地HTML代码或网络资源
  5. html5 css3 背景视频循环播放代码
  6. HTML5 标签audio添加网页背景音乐代码
  7. 我无法理解为什么我的代码中的单击选择文本
  8. js字符串与html代码互相转换时怪想法:自己解析js字符串成普通字
  9. 解决FCKEditor编辑器在浏览器返回时显示html源代码的问题

随机推荐

  1. Android(安卓)悬浮窗权限各机型各系统适
  2. Android系列之Android系列之如何成为Andr
  3. RN系列:RN使用Android原生控件或自定义组
  4. 个人开发者做一款Android(安卓)App,androi
  5. 关于android常用的按下高亮的展示
  6. Android 学习1----控件的学习
  7. Android的图形显示原理(GDI)一
  8. Android 事件分发机制源码
  9. Android(安卓)ColorMatrix类图像颜色处理
  10. [置顶] Android曙光集群发来的邀请函