Sunday, August 17, 2014

About .htaccess file and Ajax request response using json

 htaccess file
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|javascript|images|robots\.txt)
RewriteRule ^(.*)$ /codeIgniter-learning/index.php?/$1 [L]


.htaccess file used for while accessing function or file in sub folder that time this .htaccess file used.

in last line contains "codeIgniter-learning" this is your project main folder name, so change this much only, remaining just copy and paste it in side .htaccess file...

Ajax request response using json
    $.ajax({
                type:'POST',
                url:baseURL+'site/controller name/fun_name',
                data:{user:user},
                dataType:'json',
                success:function(response){
                    if(response.status_code == '1'){
                        alert(response.message);
                        return; // optinal
                        }else
                        {
                        alert(response.message);
                        }
                }
            });
            // php function
            public function fun_name(){
            $return['status_code'] = 0;
            if(some_condition){
            // if its true set
            $return['status_code'] = 1;
            $return['message'] = 'Very Success';
            }
            else{
            $return['message'] = 'Unsuccess';
            }
            }


 

No comments:

Post a Comment