SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Location
    Limbo
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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,

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Location
    Limbo
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    Code:
    // Function to handle ajax.
    function sendValue(str){
        
        // post(file, data, callback, type); (only "file" is required)
        $.post(
            
        "ajax.php", //Ajax file
        
        { sendValue: str },  // create an object will all values
        
        //function that is called when server returns a value.
        function(data){
            $('#display').html(data.returnValue);
        }, 
        
        //How you want the data formated when it is returned from the server.
        "json"
        );
        
    }
    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,

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Evangelist
    Join Date
    Sep 2006
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    Code:
    <?php
    
    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.


Bookmarks

Posting Permissions

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