Friday, February 22, 2019

jquery ajax request with json response

$.ajax({
                        type:'POST',
                        url:'http://mysite.com/url',
                        data:{fieldname: 'fieldvalue'},
                        dataType: "json",
                        success: function(data , status, xhr) {
                              alert('ajax request successful');

                        }, fail:function(data){

                                alert('ajax request failed');
                        }
 });

Friday, February 15, 2019

QR-CODE BARCODE | Scanning field jquery useful script | focus in focus out

  //if scan field exists then focus the field after every second

 if($('.focus-me').length > 0){   

         setInterval(function(){
             $('.focus-me').focus();
         },1000);
       
        //if scan field is not focused then hide "scanner ready" message

         $(".focus-me").focusout(function(){
              $('.focus-in').hide();
              $('.focus-out').fadeIn(500);
         });
       
         //if scan field is focused then hide "scanner not ready" message
         $(".focus-me").focusin(function(){
              $('.focus-out').hide();
              $('.focus-in').fadeIn(500);
         });
       
         //reset the field
         $(document).on('keyup',function(e){
           
                  if (e.key === ' ' || e.key === 'Spacebar') {
                      e.preventDefault();
                      $('.focus-me').val('');
               
                  }
      
         });
       
     }

htaccess Force HTTPS redirect on Subdomain folder and remove www

 Follow is the code

RewriteEngine On
RewriteCond %{SERVER_PORT} 80

#force https
RewriteCond %{REQUEST_URI} subfolder
RewriteRule ^(.*)$ https://www.fdhlpk.com/subfolder/$1 [R,L]

#Remove www from the URL
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]

Wednesday, January 30, 2019

yii2 search where not in condition usage

suppose we have two parameters to check

Like for example

where country_id = 4  AND city_id not in (2,3,4)

then using yii2 we can do the following

 Members::find()->select(['id','name'])->where(['country_id'=>4])->andWhere(['not in','id',[2,3,4]])->all();

Thursday, January 24, 2019

MySQL - replace first occurrance of string part - Example phone

Example for removing prefix + or 00 from phone number


we can replace first occurrence of string by using following methods using mysql functions REPLACE() , LEFT , INSTR(), LOCATE(), SUBSTRING()


To replace +  example (1 character)
SET @phone= '+923333333333';
SELECT  CONCAT(REPLACE(LEFT(@phone, INSTR(@phone, '+')), '+', ''), SUBSTRING(@phone, INSTR(@phone, '+') + 1)) as updated_phone;



Updating in DB:

Update [table] set phone = CONCAT(REPLACE(LEFT(@phone, INSTR(@phone, '+')), '+', ''), SUBSTRING(@phone, INSTR(@phone, '+') + 1))




To  replace 00 example (2 characters)
SET @phone= '00923333333333';
SELECT  CONCAT(REPLACE(LEFT(@phone, locate(@phone, '00')), '00', ''), SUBSTRING(@phone, instr(@phone, '00') + 2)) as updated_phone;



Updating in DB:
UPDATE [table] set phone = CONCAT(REPLACE(LEFT(@phone, locate(@phone, '00')), '00', ''), SUBSTRING(@phone, instr(@phone, '00') + 2))