Jquery Ajax Login Without a login.php file

Hi, I’m fairly new to this jQuery but after playing with it a little I’ve figured out how powerful it is. Well, I’ve been trying to implement it in my login system. However, all tutorials I’ve seen needed to link to a file which was only the function login.php. But this is not exactly what I wanted. All my functions are in functions.php and I have a login function which is easily called out by saying loginuser($username, $password) and I am wondering if I would be able to just call that in the javascript script something with some php tags? How would I go by doing this, or is there another way instead of having a file like login.php linked within my javascript.

Thank you,

What I would like to do is instead of putting an ajax.php file, would be to declare my php function right there

What do you mean by declare here? You want to declare a PHP function right there within JavaScript? Do you mean to call a PHP function instead of script file (ajax.php)? If you mean to ask that, then as far as I know this is not possible. It is not possible to call any PHP or any server side function in/with JavaScript not only with jQuery. I am sorry if I don’t understand what you mean or if I over-understood.

You could include an ‘action’ in your ajax request to your php page. But you will still need a php function to ‘catch’ the action and execute said function.


if(isset($_POST['action']) && $_POST['action'] == 'login')
    loginuser($_POST['username'], $_POST['password']);


Of course this doesn’t consider any security options you will have to decide how you cleanse the data.

I apologize if this post hasn’t been clear. What I would like to do is the following:

This is the generic thing I’ve been seeing from an jquery ajax request.

// Function to handle ajax.
function sendValue(str){
    // post(file, data, callback, type); (only "file" is required)
    "ajax.php", //Ajax file
    { sendValue: str },  // create an object will all values
    //function that is called when server returns a value.
    //How you want the data formated when it is returned from the server.

What I would like to do is instead of putting an ajax.php file, would be to declare my php function right there. Is that possible? I don’t really want to have to have plenty of files in my functions folder of just declaring whats in my functions.php file… It seems illogical to me if that is the only way to possibly do it, but please tell me if it is the case.

Thank you,