karlm Posted September 5, 2011 Share Posted September 5, 2011 Hello, gonna make this as simple as possible. I apparently receive two different responses. The only difference is that I 'include' a seperate class in the second attempt (which I do not even use) and in the first attempt I leave the 'include' file out. Heres some code. js/ajax.js file " $.ajax({ type: "GET", url: "classes/login.php", data: 'password=kebab', success: function(resp){ alert(resp); // see if(resp == "denied"){ alert('you are not allowed in here!'); }else{ alert('welcome master!'); } }, error: function(e){ alert('Error: '); } }); " Then the FIRST attempt 'login.php' file. " <?php require_once 'dbQuery.php'; // dbQuery.php file does not affect the outcome //require_once 'an_empty_file.php'; // in the first attempt I have removed this file from being included. $obj = new dbQuery(); $sql = "SELECT * FROM users WHERE password='".$password."';"; // the password in the database is infact "pizza", kebab was never found. $result = $obj->getDbQuery($sql); if (mysql_num_rows($result)) { // if the password was found then TRUE $echo = "granted"; } else{ // password not found, buhu $echo = "denied"; } echo $echo; ?> " In this attempt (ther one above). It worked the alert() I had put in the ajax function reads out "denied". Second attempt is exactly the same but I have included the 'an_empty_file.php'. Here is that file. classes/an_empty_file.php " <?php ?> " What makes this all weird? In the second attempt with the file included, the alert() ALSO reads out "denied". So both attempts return the exact same string/text "denied". But when arriving to my if function the first attempt reads out "'you are not allowed in here!", while the second one reads out "welcome master!". I have tried include and require_once. It is weird that my connection class works. but not the other file? Where have I messed up? Quote Link to comment https://forums.phpfreaks.com/topic/246495-ajax-response-problem-php-include-file-prime-suspect/ 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.