In this example we use 2 php page , FirstPage_GET.php for request and
ajax_second_page_GET.php for response..
FirstPage_GET.php
<html> if (this.readyState == 4 && this.status == 200) |
ajax_second_page_GET.php
<?php if ($_SERVER["REQUEST_METHOD"] == "GET") { if(!empty($_GET["PrimCategory"])) { $p_CategoryType2=rawurldecode($_GET["CategoryType"]); if($p_CategoryType2=="Vegetables") { echo "<option>Carrot</option><option>Broccoli</option><option>Spinach</option>"; } if($p_CategoryType2=="Fruits") { echo "<option>Banana</option><option>Apple</option><option>Mango</option>"; } if($p_CategoryType2=="Flower") { echo "<option>Daffodil</option><option>Sunflower</option><option>Rose</option>"; } } } ?> |
In this example also we use 2 php page , FirstPage_POST.php for request and
Ajax_Second_Page_POST.php for response..
FirstPage_POST.php
<html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <title> How to use a Http POST for an Ajax Calls? </title> <script type="text/javascript"> function getSubCategory(str){ if(str) { $.ajax({ type: "post", url: "Ajax_Second_Page_POST.php", data: {"PrimCategory": str}, cache: false, success: function (data) { $("#SubCategoryId").html(data).slideDown("slow"); } }); } else { alert("Something went wrong..."); } } </script> </head> <body> <form name="Form1" id="Form1" autocomplete="off" method="POST" action="form_submit_process.php"> <div class="col-sm-12"> <div class="form-group col-sm-6"> <label>Category Type</label> <select name="PrimCategory" id="PrimCategory" class="form-control" required onchange="getTheSubCategoryList()"> <option value="Vegetables">Vegetables</option> <option value="Fruits">Fruits</option> <option value="Flower">Flower</option> </select> </div> <div class="form-group col-sm-6" > <label>Sub Category</label> <select name="SubCategoryID" id="SubCategoryId" class="form-control"> <option value="">--select---</option> </select> </div> <div class="col-sm-12"> <div class="reset-button" id="btton"> <input type="submit" id="BTN123" value="SAVE" class="btn btn-primary" name="submit" disabled=""> </div> </div> </div> </form> </body> </html> |
Ajax_Second_Page_POST.php
<?php if(isset($_POST["PrimCategory"])) { $p_CategoryType2=$_POST["PrimCategory"]; if($p_CategoryType2=="Vegetables") { echo "<option>Carrot</option><option>Broccoli</option><option>Spinach</option>"; } if($p_CategoryType2=="Fruits") { echo "<option>Banana</option><option>Apple</option><option>Mango</option>"; } if($p_CategoryType2=="Flower") { echo "<option>Daffodil</option><option>Sunflower</option><option>Rose</option>"; } } ?> |