How to send multiple ajax request and process the multiple request one after the other and display returned data in respected drop down list
Below is the ajax code to perform the subjected action but it is implemented in a manner of elaboration instead of do it with simple one.
Here implemented separate code for each ajax request and response.
please see the below code:
Code
Code
Code
Code
Code
Code
$(document).ready(function(){Code
$("#country").change(function(){Code
var country=$("#country").val();Code
$.ajax({Code
type:"post",Code
url:"getstate.php",Code
data:'typeId='+country,Code
success:function(data){Code
$("#state").html(data);Code
}Code
});Code
});Code
});Code
Code
Code
$(document).ready(function(){Code
$("#state").change(function(){Code
var state=$("#state").val();Code
$.ajax({Code
type:"post",Code
url:"getdistrict.php",Code
data:'typeId='+state,Code
success:function(data){Code
$("#district").html(data);Code
}Code
});Code
});Code
});Code
Code
Code
$(document).ready(function(){Code
$("#district").change(function(){Code
var district=$("#district").val();Code
$.ajax({Code
type:"post",Code
url:"getward.php",Code
data:'typeId='+district,Code
success:function(data){Code
$("#ward").html(data);Code
}Code
});Code
});Code
});Code
Code
Code
$(document).ready(function(){Code
$("#ward").change(function(){Code
var ward=$("#ward").val();Code
$.ajax({Code
type:"post",Code
url:"getslum.php",Code
data:'typeId='+ward,Code
success:function(data){Code
$("#slum").html(data);Code
}Code
});Code
});Code
});Code
Code
Code
Code
Country :Code
-select your country-Code
<?phpCode
error_reporting(E_ALL);Code
ini_set('display_errors', 1);Code
include "dbconfig.php";Code
$result=sqlsrv_query($conn,"SELECT [CountryId],[Country] from toilet_Country order by Country");Code
while($country=sqlsrv_fetch_array($result)){Code
echo "$country[Country]";Code
} ?>Code
State : Code
-select your state-Code
District :Code
-select your District-Code
Code
Ward :Code
-select your ward-Code
Code
Slum :Code
-select your slum name-Code
Code
Code
Code
CSS
And i have written code in separate files to retrieve country,state,district information from database.
I am unaware of these ajax call request and response and looking for advise how can i make this code portable.
Thanks in advance.
Nanhe SiddiqueRank #1,103 · 1.7K reputationPosted May 18, 2015, 12:35 AM EDT