punk_runner Posted March 1, 2011 Share Posted March 1, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/229195-using-ajax-with-oop-php/ Share on other sites More sharing options...
trq Posted March 1, 2011 Share Posted March 1, 2011 Ajax is no different, you make get or post requests. Quote Link to comment https://forums.phpfreaks.com/topic/229195-using-ajax-with-oop-php/#findComment-1181036 Share on other sites More sharing options...
punk_runner Posted March 1, 2011 Author Share Posted March 1, 2011 Yes but it isn't correct OOP to pass $_GET or $_POST to a class, you pass it through a setter method etc... Quote Link to comment https://forums.phpfreaks.com/topic/229195-using-ajax-with-oop-php/#findComment-1181039 Share on other sites More sharing options...
KevinM1 Posted March 1, 2011 Share Posted March 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/229195-using-ajax-with-oop-php/#findComment-1181044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.