I'm new to php and ajax. I want to run simple code of ajax with php but the code is not working as intended. I want load some text in the page when onchange happen
source code ajax.php
<select id='mySelect' onChange="MyFunction()">
<option value='option1'>Option1</option>
<option value='option2'>Option2</option>
<option value='option3'>Option3</option>
</select>
<script>
function MyFunction()
{
var params="myName=2";
var xmlHttp;
if(window.XMLHttpRequest)
xmlHttp=new XMLHttpRequest();
else
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("GET","edittest.php",true);
if(xmlHttp)
{
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4 && xmlHttp.status==200)
{
alert(document.getElementById('mySelect').value);
}
}
}
xmlHttp.send(params);
}
</script>
edittest.php source code
<?php
if(isset($_GET))
{
for($i=0;$i<1000;$i++)
{
echo($_GET['myName']);
}
}
?>