193
rated 0 times
[
195]
[
2]
/ answers: 1 / hits: 22064
/ 11 Years ago, wed, november 13, 2013, 12:00:00
I'm new to AJAX and trying to learn basic calls through AJAX and jQuery.
I have a simple drop list of countries, where I want to select a particular country and send the value of it to server, where it would process which country was selected and give particular output. For now, it could just echo simple output in php file. There is some kind of problem with this code. I would appreciate if anyone could help me with it. thanks
<html>
<head>
<script src=http://code.jquery.com/jquery-1.9.1.js></script>
<script type=text/javascript>
function load()
{
$.ajax({
type:GET,
url: test.php,
data: { country: $(#country).val()}
}).done(function(msg){
$(#right #myDiv).html(msg);
});
}
</script>
</head>
<body>
<div id=main>
<div id=left>
Select Country: <select id=country name=country>
<option value=germany>Germany</option>
<option value=england>England</option>
</select>
<input type=button value=Run Query onClick=load()></input>
</div>
<div id=right>
<div id=myDiv></div>
</div>
</div>
test.php
<?php
$name=$_GET['country'];
if($name==England)
{
echo Works;
}
else
{
echo doesnt Work;
}
?>
?>
More From » php