PHP And AJAX

Discussion in 'PHP' started by onetouch, Apr 5, 2010.

  1. #1
    I want to make signup from using php and ajax, can anyone help me with it? I am new to ajax so dont know how to do it.

    Thanks
     
    onetouch, Apr 5, 2010 IP
  2. dweebsonduty

    dweebsonduty Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    Digital Goods:
    1
    #2
    I like using jquery for ajax.

    So you would want to look into using jquery and the .post and .get functions that it offers.

    Jquery Code Example:
    What you see here is when the button that has an id="logmein" is clicked it sends the textboxes with the ids of password and user to user_login.php. Then it requests a response and expects JSON to come back. If the php echos success=1 then the login is good and you can send them to the main page with their session information.

    $("#logmein").click(function(){
    	$.post("user_login.php",
    	{
    	user: $("#user").val(),
    	password: $("#password").val()
    	},function(data){
    	if (data.success == 1){
    	location.href= "user_index.php?user="+data.user+"&session="+data.session;
    	}
    	},"json");
    	});
    
    Code (markup):
    In you php you would take the username and password posts and compare them to your database and then output your data in json format.

    Example:
    
    $jsonoutput = array('user'=>$user,'session'=>$session,'success'=>1);
    echo json_encode($jsonoutput );
    
    PHP:
    Hope this helps
     
    dweebsonduty, Apr 5, 2010 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    I agree, use a pre-developed library if you want the easiest Ajax entry point. Personally, I like prototype, but jquery, and mootools are also great libraries.
     
    jestep, Apr 6, 2010 IP
  4. Narrator

    Narrator Active Member

    Messages:
    392
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    80
    #4
    Learning jquery or mootools is definately the best way. I learned ajax the hard way, and libraries cut development time in half.
     
    Narrator, Apr 6, 2010 IP
  5. Cloud Computing Forum

    Cloud Computing Forum Guest

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    When I started learning aJax XAJAX php library was the easiest way to get started, it's pretty easy to use and does everything you will need.

    Just read the tutorial on here: http://xajaxproject.org/
     
    Cloud Computing Forum, Apr 7, 2010 IP