Jump to content

functions not defined


c_pattle

Recommended Posts

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

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>");
  }
}

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?

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.