I am trying to display the full name of the selected city from the dropdown in the paragraph. But the jQuery ajax call is giving no output.
index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Learn Javascript</title>
<script src="jquery-1.10.2.min.js"></script>
</head>
<body>
<select id="states">
<option> LDH </option>
<option> JLD </option>
<option> CHD </option>
</select>
<br/>
<p>The Full name is: <span id="fullname"></span></p>
<script>
$(document).ready(function() {
$('#states').change(function() {
selectedState = $('#states option:selected').text();
$.get('learn.php?state='+selectedState, function(data) {
$('#fullname').html(data);
});
});
});
</script>
</body>
</html>
learn.php
<?php
switch ($_GET['state']) {
case 'LDH' :
echo 'Ludhiana';
break;
case 'JLD' :
echo 'Jalandhar';
break;
case 'CHD' :
echo 'Chandigarh';
break;
}
?>
When the dropdown state is changed, this is supposed to print the full name of the selected city by retrieving data from the php file.
$_GET [$state]should be$_GET['state']$_GET['state']& not working.selectedState = $(this).val();? and tryalert(selectedState );you'll get to know, wthr any data being passed or not.