www.webdeveloper.com
Results 1 to 3 of 3

Thread: how to return data from php to jquery AJAX

  1. #1
    Join Date
    Apr 2010
    Location
    Brooklyn NY
    Posts
    104

    how to return data from php to jquery AJAX

    I've got an ajax call that runs a password verification. The username/password work fine but I can't get the php to send data to to the AJAX, instead it just echoe's the result in an alert box


    ////// JQUERY //////
    Code:
    $.ajax({
    	type: 'POST',
    	url: 'login.php',
    	data: datastring,
    	success: function(result) {
    		alert(result + 'worked');//     does nothing
    	}
    });
    //////// PHP ////////
    Code:
    <?php
    	$user_name = $_POST['user_name'];
    	$password = md5($_POST['password']);
    	
    	$dbc = mysqli_connect('seahorse.fatcowmysql.com','harhar','trees','des')
    		or die('Error connecting to Server');
    				
    	//$my_user_name = mysql_real_escape_string($user_name);
    	//$my_password = mysql_real_escape_string(md5($password));
    		
    	$query = 'SELECT * FROM members WHERE username = "' . $user_name . '"';
    	
    	$result = mysqli_query($dbc,$query);
    	
    	if ($my_row = mysqli_fetch_array($result)) {
    		
    		if ($user_name == $my_row['username'] && $password == $my_row['password']) {
    			echo 'true';//    alerts this line in the browser
    		} else {
    			echo 'false';
    		}
    	} else {
    		echo 'false';
    	}
    ?>

  2. #2
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    perhaps

    Code:
    $.ajax({
    	type: 'POST',
    	url: 'login.php',
    	data: datastring,
    	success: function(data) {
    		alert(data+ 'worked');//     does nothing
    	}
    });

  3. #3
    Join Date
    Apr 2010
    Location
    Brooklyn NY
    Posts
    104

    resolved

    works thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles