hi,
I have a continous ajax request asking for some data
that is to be displayed in textarea.
Now my problem, how do I display the data as soon as page is loaded.
My template code is as follows:
<html>
<head>
<script type="text/javascript" src="/jquerycall/"></script>
<script type="text/javascript">
$(document).ready(function()
{
var setid = 0;
var s = new String();
var my_array = new Array();
var no_of_lines = 0;
var array_copy = new Array();
var fname ="{{fname}}"
var pid = "{{pid}}"
function displayfile()
{
var text = $("#textid").val();
if(text == "")
{
no_of_lines = 0;
}
else
{
array_copy = text.split("\n");
no_of_lines = array_copy.length;
}
/*$("#tid").val(no_of_lines)*/
$.ajax({
type:"POST",
url:"/displayoutput/",
datatype:"json",
data:{text:no_of_lines,filename:fname,pid:pid},
success:function(data)
{
s = data.filedata;
if(s == "")
{
clearInterval(setid);
}
my_array = s.split("\n");
displaydata(my_array);
}
});
}
function displaydata(my_array)
{
var i = 0;
var length = my_array.length;
for(i=0;i<my_array.length;i++)
{
var line = my_array[i] + "\n";
line = line.replace(/</g,"<");
$("#textid").append(line);
$("#tid").val(line)
}
}
$("form").submit(function(event)
{
setid = setInterval(displayfile,1000);
event.preventDefault();
});
$("#stop").click(function()
{
clearInterval(setid);
});
});
</script>
</head>
<body>
<form method="post">
<input type="submit" value="Click Me"/><br><br>
<button type="button" id="stop">Stop</button><br><br>
<textarea id="textid" disabled="true" readonly="true" rows=30 cols=100></textarea><br><br>
</form>
</body>
</html>
Here, the data is loaded when I click the "Click Me"
But I want the data to be loaded as soon as page is loaded
Any suggestions will be valuable
Thanks in advance
tazim