Jump to content

Recommended Posts

So I have a simple login modal box (jQuery) that pops up when you click a "login" link... I also have a nice PHP class to handle authentication. I need to pass the username and password values to the class with AJAX and return TRUE or FALSE, or whatever, and then redirect to the user account or display an error.

 

How do I pass these values into a class and get the results back with AJAX? I know how to do it with $_GET but I need to pass them as arguments like this:

 

$login = new Login($username, $password);

$result = $login->getResult();

 

How does that fit in with AJAX so I don't have to reload the page if there's an error?

 

Link to comment
https://forums.phpfreaks.com/topic/229195-using-ajax-with-oop-php/
Share on other sites

Yes but it isn't correct OOP to pass $_GET or $_POST to a class, you pass it through a setter method etc...

 

You don't need to pass entire superglobals to the object.  Parse them like you normally would.  Your Ajax call should be aimed at a PHP script that can handle the request regardless of whether it was sent asynchronously or not.  Aside from potentially having to return some JSON, there shouldn't be much difference on the PHP side of things than what you'd normally do.

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.