While developing a website to search through my python database, I encountered an issue. The non-JavaScript version was functioning flawlessly. However, when attempting to implement AJAX so that the page would not have to be refreshed each time, I faced a problem - nothing happened upon clicking the search button. Can anyone help figure out why this is happening?
<script language="javascript">
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
function getData(){
if(xmlhttp) {
var obj = document.getElementById("search-results");
xmlhttp.open("GET","http://127.0.0.1:8000/search/?name=i&city=o",true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 &&
xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseXML;
}}
xmlhttp.send(null);
}}
</script>
</head><body>
<form id="search-form" action="" method="get">
<input type="text" name="name" id="name">
<input type="text" name="city" id="city">
<input type="button" value="Search" onclick = "getData()">
</form>
<div id="search-results"></div></body>