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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.