php - how to send multiple ajax request and process the multiple request -
below ajax code perform subjected action implemented in manner of elaboration instead of simple one.
here implemented separate code each ajax request , response.
please see below code:
<html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery- 1.7.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#country").change(function(){ var country=$("#country").val(); $.ajax({ type:"post", url:"getstate.php", data:'typeid='+country, success:function(data){ $("#state").html(data); } }); }); }); </script> <script type="text/javascript"> $(document).ready(function(){ $("#state").change(function(){ var state=$("#state").val(); $.ajax({ type:"post", url:"getdistrict.php", data:'typeid='+state, success:function(data){ $("#district").html(data); } }); }); }); </script> <script type="text/javascript"> $(document).ready(function(){ $("#district").change(function(){ var district=$("#district").val(); $.ajax({ type:"post", url:"getward.php", data:'typeid='+district, success:function(data){ $("#ward").html(data); } }); }); }); </script> <script type="text/javascript"> $(document).ready(function(){ $("#ward").change(function(){ var ward=$("#ward").val(); $.ajax({ type:"post", url:"getslum.php", data:'typeid='+ward, success:function(data){ $("#slum").html(data); } }); }); }); </script> </head> <body> country : <select name="country" id="country"> <option>-select country-</option> <?php error_reporting(e_all); ini_set('display_errors', 1); include "dbconfig.php"; $result=sqlsrv_query($conn,"select [countryid],[country] toilet_country order country"); while($country=sqlsrv_fetch_array($result)){ echo "<option value = $country[countryid]>$country[country]</option>"; } ?> </select> <br><br> state :   <select name="state" id="state"> <option>-select state-</option> </select> <br><br> district : <select name="district" id="district"> <option>-select district-</option> </select> <br><br> ward : <select name="ward" id="ward"> <option>-select ward-</option> </select> <br><br> slum : <select name="slum" id="slum"> <option>-select slum name-</option> </select> <br><br> </body> </html>
and have written code in separate files retrieve country,state,district information database.
i unaware of these ajax call request , response looking advise how can make code portable.
thanks in advance.
Comments
Post a Comment