My external javascript file called ajax.js has an Ajax function like so:
function webservice(x){
jQuery.ajax
({
//some code here
});
Data = function(data){
if(x==1)
{
for(i=0;i<10;i++)
{
webservice(i);
alert("Onload");
}
}
else
if(x==5)
{
for(i=0;i<10;i++)
{
webservice(i);
alert ("Onclick");
}
}
}
In another html page named webservice.html, I have the following code:
<html>
<title>Call web service</title>
<head>
<script type="text/Javascript" src="jquery-1.9.1.js"></script>
<script type = "text/javascript" src="ajax.js"></script>
<script>
window.onload=function()
{
webservice(1)('onload'); //call 1
}
</script>
</head>
<body>
<input id="webservice" type = "button" name = "webservice" value = "Call Webservice"
onclick="webservice(5)"/>
</body>
</html>
I am trying to call the same function both on the onLoad event and the onclick of a button so that they run simultaneously. However, when onload runs multiple times and then I click the button, the previous instances of onload stop. How can I make them run concurrently from where they left off or display alerts one after the other?
If anyone has alternative methods, I would appreciate the help.