I am displaying a list of country in the drop down list, retrive it from the database . and i need to display price for the selected country based on the options chosen by the customers in the drop down list without that page getting refreshed.
the url i m passing in ajax is not calling the php file url: "cities.php",
is any one help me how to do that any suggestions.
i am use exec php plugin to write the php code in the page.
This is my code
<?php
// Establish a database connection (adjust address, username, and password)
$con= mysqli_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
mysql_select_db("geo_ip");
// Create a query string
$query = "SELECT countryFROM geo_ip ";
$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() );
echo "<select name=myselect onChange='get_cities(this.value)'>";
while($row=mysql_fetch_array($result)){
echo "<OPTION VALUE=".$row['country'].">".$row['country']."</OPTION>";
}
echo "</select>";
echo "<select name='city' id='city'></select>"; //We have given id to this dropdown
?>
<script>
function get_cities(country)
{
$.ajax({
type: "POST",
url: "cities.php", /* The country id will be sent to this file */
beforeSend: function () {
$("#price").html("<option>Loading ...</option>");
},
data: "country="+country,
success: function(msg){
$("#price").html(msg);
}
});
}
</script>
$wpdb
, as already mentioned, and 2) not using the AJAX API – s_ha_dum Apr 22 at 14:01