Welcome Guest, Not a member yet? Register   Sign In
Simple ajax call page??
#4

[eluser]Guest[/eluser]
Thanks so much guys! With your help, i got it working :-)
(There are some problems, but i will explain them at the end)

I thought id show exactly what i did, in case anyone else ever finds this post and needs to work it out.

In my validate script, i have the following:

Code:
required: true,
                minlength: 4,
                remote: "../ajax/checkusername"
            },

then, in the ajax.php file, located in SITE\system\application\controllers

i have this:

Code:
<?php
//if (!defined('BASEPATH')) exit('No direct script access allowed');
class Ajax extends Controller {

    function index()
    {
        echo 'false';
    }

    function checkusername()
    {
        
        $request = strtolower($_REQUEST['username']);
        
        $query = $this->db->query('SELECT userID FROM users WHERE LOWER(userName) = "'. $request .'"');
        if ($query->num_rows() > 0){
            echo 'false';
        } else {
            echo 'true';
        }
        
        
    }
    
}
?>

It really is great :-), as i only have to have 1 ajax.php file -- and then just add more functions as i need them, and call them like this ../ajax/checkemail or ../ajax/otherfunction instead of the 100's of little ajax files i used to do.

I had to change one line in the jquery.validate.js plugin file, and that was at line 932, i had to add type: "POST",

Code:
$.ajax($.extend(true, {
                    url: param,
                    mode: "abort",
                    type: "POST",


Thanks kgill and mcr_rm :-) great advice.

I just have two problems now...

I had to comment out the line to check if the file is being loaded directly or not, as it stops it working...

Code:
//if (!defined('BASEPATH')) exit('No direct script access allowed');


This dosnt really matter, though.

Another problem was that i had to disable compression in my config.php file...

Code:
$config['compress_output'] = FALSE;

Otherwise i was getting an error.

I did read there was another way to turn on compression in the php.ini file -- so i will have to look into that (unless anyone wants to post the answer?)

Thanks again for the help!

Regards,


Messages In This Thread
Simple ajax call page?? - by El Forum - 01-13-2010, 02:46 PM
Simple ajax call page?? - by El Forum - 01-13-2010, 03:42 PM
Simple ajax call page?? - by El Forum - 01-13-2010, 03:52 PM
Simple ajax call page?? - by El Forum - 01-14-2010, 04:59 AM
Simple ajax call page?? - by El Forum - 01-14-2010, 05:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB