I am facing a problem while applying ajax in my login script.
My login form is :
Ajax code is:Code:<form action="" id="contactform" onsubmit="return loadXMLDoc();"> <div id= "login"> <font face="Georgia" size="-1"> <input type='button' id='button' name='login_user' value='Login' onclick='loadXMLDoc();'/> </form> <span id="txtHint"></span>
Code:<script type="text/javascript"> var ajaxRequest; function ajaxFunction(){ try{ ajaxRequest = new XMLHttpRequest(); }catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); }catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); }catch (e){ alert("Your browser broke!"); return false; } } } } function processRequest() { if (req.readyState == 4) { var ajaxDisplay = document.getElementById('txtHint'); ajaxDisplay.value = ajaxRequest.responseText; } } function loadXMLDoc() { ajaxFunction(); // Here processRequest() is the callback function. var url = 'login.php'; if (!target) var target = document.getElementById("textfield").value; if (!target1) var target1 = document.getElementById("textfield2").value; var mainurl = url + "?uname=" + target; mainurl = mainurl + "&pass=" + target1; mainurl = mainurl + "&login=" + '1'; alert(mainurl); ajaxRequest.open("POST", mainurl, true); ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); ajaxRequest.onreadystatechange = processRequest; ajaxRequest.send(mainurl); } </script>
Now, whenever I click login button, nothing happens. I have checked url and it shows login.php?uname=&pass=&login=1
The script is not able to call login.php
login.php is [kept simple for testing]
After clicking login button....I am getting any of the messages...PHP Code:<?php
// makes sure they filled it in
if((!$_GET['uname']) || ($_GET['uname']=='') || (!$_GET['pass']) || ($_GET['pass']=='')) {
$response="Please fill";
?>
<script type="text/javascript">
alert('please fill');
</script>
<?php
echo $response;
die(); }
?>
please help...![]()


Reply With Quote

Bookmarks