用jquery调用ajax - 解析传入的反馈数据

时间:2022-10-18 14:21:08

I got a server-side script that I call with jQuery ajax method. It can take quite a while for it to process data set. After each row of input data is processed, it prints out a "OK <row id>" to output. The content type is plain/text.

我有一个服务器端脚本,我用jQuery ajax方法调用。处理数据集可能需要一段时间。处理完每一行输入数据后,它会输出一个“OK ”来输出。内容类型是纯文本/文本。

What I want is to get this output in my jquery function, parse it as it comes and display some kind of feedback information to the user. As it can take up to 20-30 minutes to process all the data...

我想要的是在我的jquery函数中获取此输出,在它到来时解析它并向用户显示某种反馈信息。因为处理所有数据可能需要20-30分钟......

How can I do this in jQuery (the server script prints this out alredy). If I use the code below, I get the success function called after the script finishes its run.

我怎样才能在jQuery中执行此操作(服务器脚本将此打印出来)。如果我使用下面的代码,我会在脚本完成运行后调用成功函数。

$.ajax({
 type: "POST",
 url: "script.cgi",
 data: data,
 success: function() { 
   // do something
   alert ("OK");
 }
});

1 个解决方案

#1


1  

You can't accomplish what you want with a single Ajax call. You will need some server-side interaction (storing the progress in a database or in the session) and then poll the server to get the status.

单个Ajax调用无法实现您想要的功能。您将需要一些服务器端交互(将进度存储在数据库或会话中),然后轮询服务器以获取状态。

#1


1  

You can't accomplish what you want with a single Ajax call. You will need some server-side interaction (storing the progress in a database or in the session) and then poll the server to get the status.

单个Ajax调用无法实现您想要的功能。您将需要一些服务器端交互(将进度存储在数据库或会话中),然后轮询服务器以获取状态。