I have five ajax simultaneously in my .js file. They are taking very long server response time(minimum 5sec). If I call them one by one then each of them executes within 1 sec.
here is my js code.
$j('.combo').change(function(){
filter_area();
filter_subarea();
filter_propertytype();
filter_pricerange();
filter_bedrooms();
});
function filter_area()
{
var area_id = $j('#inputarea').val();
var operation = $j('#property').val();
var subarea_id = $j("#inputsubarea").val();
var propertytype = $j("#inputpropertytype").val();
var pricerange = $j("#inputpricerange").val();
var bedrooms = $j("#inputbedrooms").val();
$j.ajax({
type:"GET",
url:'/custom_action.php',
data:'action=filter_area'+'&operation='+operation+'&area_id='+area_id+'&subarea_id='+subarea_id+'&propertytype='+propertytype+'&pricerange='+pricerange+'&bedrooms='+bedrooms,
}).done(function(response){
$j('#inputarea').html(response);
});
}
function filter_subarea()
{
var area_id = $j('#inputarea').val();
var operation = $j('#property').val();
var subarea_id = $j("#inputsubarea").val();
var propertytype = $j("#inputpropertytype").val();
var pricerange = $j("#inputpricerange").val();
var bedrooms = $j("#inputbedrooms").val();
$j.ajax({
type:"GET",
url:'/custom_action.php',
data:'action=filter_area'+'&operation='+operation+'&area_id='+area_id+'&subarea_id='+subarea_id+'&propertytype='+propertytype+'&pricerange='+pricerange+'&bedrooms='+bedrooms,
}).done(function(response){
$j('#inputsubarea').html(response);
});
}
function filter_propertytype()
{
var area_id = $j('#inputarea').val();
var operation = $j('#property').val();
var subarea_id = $j("#inputsubarea").val();
var propertytype = $j("#inputpropertytype").val();
var pricerange = $j("#inputpricerange").val();
var bedrooms = $j("#inputbedrooms").val();
$j.ajax({
type:"GET",
url:'/custom_action.php',
data:'action=filter_area'+'&operation='+operation+'&area_id='+area_id+'&subarea_id='+subarea_id+'&propertytype='+propertytype+'&pricerange='+pricerange+'&bedrooms='+bedrooms,
}).done(function(response){
$j('#inputpropertytype').html(response);
});
}
function filter_pricerange()
{
var area_id = $j('#inputarea').val();
var operation = $j('#property').val();
var subarea_id = $j("#inputsubarea").val();
var propertytype = $j("#inputpropertytype").val();
var pricerange = $j("#inputpricerange").val();
var bedrooms = $j("#inputbedrooms").val();
$j.ajax({
type:"GET",
url:'/custom_action.php',
data:'action=filter_area'+'&operation='+operation+'&area_id='+area_id+'&subarea_id='+subarea_id+'&propertytype='+propertytype+'&pricerange='+pricerange+'&bedrooms='+bedrooms,
}).done(function(response){
$j('#inputpricerange').html(response);
});
}
function filter_bedrooms()
{
var area_id = $j('#inputarea').val();
var operation = $j('#property').val();
var subarea_id = $j("#inputsubarea").val();
var propertytype = $j("#inputpropertytype").val();
var pricerange = $j("#inputpricerange").val();
var bedrooms = $j("#inputbedrooms").val();
$j.ajax({
type:"GET",
url:'/custom_action.php',
data:'action=filter_area'+'&operation='+operation+'&area_id='+area_id+'&subarea_id='+subarea_id+'&propertytype='+propertytype+'&pricerange='+pricerange+'&bedrooms='+bedrooms,
}).done(function(response){
$j('#inputbedrooms').html(response);
});
}
Please see images in image1 if I execute all ajax then it takes 4-5 sec to complete all requests. and in image2 I have executed only one ajax out of them then it finished itself within one sec.
and also I have not used any session at my server side script. It is just simple PHP script to handle request and create response.
I have googled to find how to use multiple ajax simultaneously and found the below link-
Two simultaneous AJAX requests won't run in parallel
Since this uses session in server side script, so it has used session_write_close()
, but I have no used of any session in my server side script, still I tried to put this function before sending my response, but nothing worked.
Can any one please tell me what I have to do to execute all ajax request concurrently.?
If any thing is not clear please ask.