Abel1416 Posted April 17, 2021 Share Posted April 17, 2021 I am making a simple login with jQuery ajax but I have a little problem. I get no response from my loginizer.php . My login page (index.php) contains the following code. <form action="loginizer.php" onsubmit="return submitForm();" method="post" class="box"> <div id="error" ></div> <input id="matNo" name="matNo" class="input is-link is-rounded" type="text" placeholder="e.g. 2015/1/55852EE"> <input id="password" name="password" class="input is-link is-rounded" type="password" placeholder="********"> <button type="submit" id="submit" name="submit" class="button is-link is-small">Login</button></form> My loginizer php contains the code: <?php if(isset($_POST['submit'])){ require("db.php"); $table="Students"; $pUser=$_POST['matNo']; $pPass=$_POST['password']; $sql= $conn->prepare("SELECT * FROM $table WHERE Email=?"); $sql->bind_param("s",$pUser); $sql->execute(); $result = $sql->get_result(); $row = $result->fetch_assoc(); $user= $row['Email']; $pass = $row['Password']; $errMsg="Invalid Credentials"; $errMsg1="username doesn't exist"; $successMsg = "successLogin"; if($result->num_rows < 1) { echo json_encode($errMsg1); exit; } elseif($pUser == $user && $pPass !== $pass) { echo json_encode($errMsg); exit; } else{ echo json_encode($successMsg); exit; } } ?> Ans lastly myJquery.js file which contains: function submitForm() { var userid=$("#matNo").val(); var pass=$("#password").val(); if(userid!="" && pass!="") { $("#submit").html("Please Wait..."); $.ajax ({ type:'post', url:'loginizer.php', data:{ matNo:userid, password:pass }, dataType:'json', success:function(response) { if(response=="successLogin") { window.location.href="dash/home/"; } else { $("#error").html(response); //alert("Wrong Details"); } } }); } else { alert("All details are required"); } return false; } The issue is that I get blank response . If I also change the url in the jQuery/Ajax code to index.php, it comes back with a response consisting of the html of the index.php. If I remove the dataType: 'json', it's still no response. Thanks for your help in advance!!! Quote Link to comment https://forums.phpfreaks.com/topic/312477-why-am-i-getting-no-response-from-my-loginizerphp-file/ Share on other sites More sharing options...
Solution maxxd Posted April 17, 2021 Solution Share Posted April 17, 2021 The data you're sending from AJAX doesn't include a 'submit' index, which loginizer.php requires to do anything. 1 Quote Link to comment https://forums.phpfreaks.com/topic/312477-why-am-i-getting-no-response-from-my-loginizerphp-file/#findComment-1585868 Share on other sites More sharing options...
kicken Posted April 17, 2021 Share Posted April 17, 2021 Additionally, if the only thing your javascript is going to do is either redirect or show an error, then there's really no reason to use javascript / ajax at all. Just use a normal form process and keep it simple. 1 Quote Link to comment https://forums.phpfreaks.com/topic/312477-why-am-i-getting-no-response-from-my-loginizerphp-file/#findComment-1585869 Share on other sites More sharing options...
Abel1416 Posted April 17, 2021 Author Share Posted April 17, 2021 Thanks to you all!! You added to my knowledge Quote Link to comment https://forums.phpfreaks.com/topic/312477-why-am-i-getting-no-response-from-my-loginizerphp-file/#findComment-1585870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.