c_pattle Posted November 6, 2010 Share Posted November 6, 2010 I have the following AJAX request but I am getting an error when I run the script which says that the function "loadContent" is undefined. Does anyone know why this is happening? $.ajax({ type: "POST", url: "includes/inc_login.php", data: dataString, success: function(data) { if (data=="true") { $("#loading").show(); $('#lightbox_content').hide('slow', loadContent); function loadContent() { $('#login_content').show('slow', hideLoader); } function hideLoader() { $("#loading").hide(); } $("#login_content").append("<p>Login successful</p>"); } else if (data=="false") { $("#login_content").append("<p>Sorry the username and password did not much. Please try again or <a href=\"\">register here</a></p>"); } } }); Link to comment https://forums.phpfreaks.com/topic/217900-functions-not-defined/ Share on other sites More sharing options...
trq Posted November 6, 2010 Share Posted November 6, 2010 Move your function definitions up so they occur before you call them, or better still, use anonymous functions. success: function(data) { if (data == "true") { $("#loading").show(); $('#lightbox_content').hide('slow', function() { $('#login_content').show('slow', function() { $("#loading").hide(); }); }); $("#login_content").append("<p>Login successful</p>"); } else { $("#login_content").append("<p>Sorry the username and password did not much. Please try again or <a href=\"\">register here</a></p>"); } } Link to comment https://forums.phpfreaks.com/topic/217900-functions-not-defined/#findComment-1130944 Share on other sites More sharing options...
c_pattle Posted November 6, 2010 Author Share Posted November 6, 2010 Great thanks for your help. Now another problem is the if statement. It is meant to check if the data returned from the server is equal to "true". However I am finding that even if it returns something else if still think it's "true" and performs the first part of the if statement. Can you see anything wrong with how I have coded it? Link to comment https://forums.phpfreaks.com/topic/217900-functions-not-defined/#findComment-1131023 Share on other sites More sharing options...
trq Posted November 6, 2010 Share Posted November 6, 2010 Can we see includes/inc_login.php ? Link to comment https://forums.phpfreaks.com/topic/217900-functions-not-defined/#findComment-1131209 Share on other sites More sharing options...
c_pattle Posted November 7, 2010 Author Share Posted November 7, 2010 yeah sure. include ("inc_db_connect.php"); $username = $_POST['pp_username']; $password = $_POST['pp_password']; $login_sql = "select * from pp_users where pp_username=\"" . $_POST['username'] . "\" and pp_password=\"" . $_POST['password'] . "\""; $login_rs = mysql_query($login_sql, $mysql_conn); $login_result = "false"; if ($login_rs) { $login_result = "true"; } echo $login_result; Link to comment https://forums.phpfreaks.com/topic/217900-functions-not-defined/#findComment-1131469 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.