Hello
I wonder is it a good practice to do multiple Ajax calls
?
Hello
I wonder is it a good practice to do multiple Ajax calls
?
its depends on your requirement
if you want to updated your data continuously like weather information than its ok.
if you just want to update data on your page load once than call it once.
its ok if you call the page multiple time by using ajax if you are using asynchronous call to page.
Doing multiple AJAX calls is great - especially if you do them concurrently. There are a number of sources out there to do that. Here's what I use:
function ajax(url, params, callback)
{
var xmlhttp;
var paramstring = "";
for (postvar in params)
{
if (paramstring.length > 0) paramstring += "&";
paramstring += postvar + "=" + escape(params[postvar]);
}
if (window.XMLHttpRequest)
xmlhttp = new XMLHttpRequest();
else if (window.ActiveXObject)
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
else
throw new exception("XMLHTTPRequest failed to initialize.");
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", paramstring.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.onreadystatechange = function ()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200) //ok
callback(unescape(xmlhttp.responseText));
else if (xmlhttp.readyState==4)
throw new exception("XMLHTTPRequest loaded with status: " + xmlhttp.status);
}
xmlhttp.send(paramstring);
}