Written some code in my view function : This code reads a file from server . stores it in a list .passes to client def showfiledata(request):
在我的视图函数中编写了一些代码:此代码从服务器读取文件。将它存储在列表中。通过客户端def showfiledata(请求):
f = open("/home/tazim/webexample/test.txt")
list = f.readlines()
return_dict = {'list':list}
json = simplejson.dumps(list)
return HttpResponse(json,mimetype="application/json")
On, client side the $.ajax callback function receives this list of lines.
在客户端,$ .ajax回调函数接收此行列表。
Now, My Question is . I have to display these lines in a textarea. But these lines should not be displayed at once . Each line should be appended in textarea with some delay. (Use of setInterval is required as per my knowledge) . Also I am using jquery in my templates.
现在,我的问题是。我必须在textarea中显示这些行。但是这些线不应该立刻显示出来。每行应在textarea中附加一些延迟。 (根据我的知识,需要使用setInterval)。我也在我的模板中使用jquery。
The server used is Django . Please provide some solution as in some sample code will be quite helpful .
使用的服务器是Django。请提供一些解决方案,因为在一些示例代码中将非常有帮助。
1 个解决方案
#1
0
So, looks like you've got a list of lines from the server, which I assume will serialize to a JavaScript array in the library you're using. If so, then you can just pop lines off the array using setTimeout (which is better than setInterval for most animations).
所以,看起来你有一个来自服务器的行列表,我假设它将序列化到你正在使用的库中的JavaScript数组。如果是这样,那么你可以使用setTimeout从数组中弹出线条(对于大多数动画来说,这比setInterval更好)。
so, something like this:
所以,像这样:
// assuming some array named 'lines' holds your lines from the server
function appendLine(){
var currentValue = $('mytextarea').val();
var nextLine = lines.shift();
$('mytextarea').val(currentValue+nextLine);
if(lines.length > 0)
setTimeout("appendLine",5000);
}
window.setTimeout("appendLine",5000);
Probably not the most efficient way to do it, but that's the gist.
可能不是最有效的方法,但这是要点。
#1
0
So, looks like you've got a list of lines from the server, which I assume will serialize to a JavaScript array in the library you're using. If so, then you can just pop lines off the array using setTimeout (which is better than setInterval for most animations).
所以,看起来你有一个来自服务器的行列表,我假设它将序列化到你正在使用的库中的JavaScript数组。如果是这样,那么你可以使用setTimeout从数组中弹出线条(对于大多数动画来说,这比setInterval更好)。
so, something like this:
所以,像这样:
// assuming some array named 'lines' holds your lines from the server
function appendLine(){
var currentValue = $('mytextarea').val();
var nextLine = lines.shift();
$('mytextarea').val(currentValue+nextLine);
if(lines.length > 0)
setTimeout("appendLine",5000);
}
window.setTimeout("appendLine",5000);
Probably not the most efficient way to do it, but that's the gist.
可能不是最有效的方法,但这是要点。