Monday, April 15, 2013

Ajax Json Php and Parsing Array

Jquery

jQuery(document).ready(function() {

                var dataString = "tableName=campaign_master";
               
                $.ajax
                (
                    {                                      
                        dataType: "json",type: "POST", url: "getCampaign.php", data: dataString,
                        success:
                            function(data)
                            {    
                                console.log(data);
                               
                                $.each(
                                        data,
                                        function(intIndex, objValue ){
                                         $('#campaignid').append(
                                         $( "<option id="+objValue+">" + objValue + "</option>" )
                                        );
                                        }
                                        );
                               
                                              
                               
                            },
                        error:
                            function (XMLHttpRequest, textStatus, errorThrown)
                            {
                                                                                               
                            }
                    }
                )
               
            });



php

echo json_encode(databasecall returning array);

databasecall

$recordsArray = array();
        $qry = "Select auery" ;
       
        $recordsArray = $this->executeQuery($qry);
       
        foreach($recordsArray as $record)
        {
            $idArray[] = $record['cm_id'];
        }
       
        return $idArray; //returning array

Monday, February 25, 2013

Connect to facebook using localhost


Steps to connect to facebook from localhost

1. We need to trick facebook in believing we are from that we are from actual domain instead of localhost.

So what we need to do is create a host 

So go to /etc/hosts on ubuntu one can go in windows apache/hosts file and add the following

/etc/hosts

127.0.0.1       localhost
127.0.1.1       your local ip address or whatever
127.0.0.1       abo.mysite
127.0.1.1       abo.mysite

2. Now go to apache config
/etc/apache2/sites enabled/000-default and add the following

<VirtualHost abo.mysite:80>
 DocumentRoot /var/www/
    <Directory /var/www>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

 Now restart apache sudo /etc/init.d/apache2 restart and test the new locahost
http://abo.mysite this should resolve now.

3. No go to http://apps.facebook.com and create a new app after you create a app you should have settings as showin in the image below.






File index.php

require_once("library/facebook.php");

$facebook= new Facebook(array(
                'appId'  => '$appid',
                'secret' => '#appsecretkey'
            ));


$me = null;
// some random permissions
$permissions = 'publish_stream, create_event, rsvp_event, manage_pages, ads_management, user_photos';

// Session based API call.

    try {
        $uid = $facebook->getUser();
        echo $uid;
        $me = $facebook->api('/' . $uid);

    } catch (FacebookApiException $e) {
        var_dump($e);
    }

// here, check if the user has the application added
if ($me == null) {
    $loginUrl = $facebook->getLoginUrl(array(
        'canvas' => 1,
        'fbconnect' => 0,
        'req_perms' => $permissions,
        'next' => CALLBACK_URL . '?installed=1', // will be redirected to this URL after pressing "allow"
        'cancel_url' => CALLBACK_URL . '?cancel', // will be redirected here if app is not allowed
    )
    ); // end of array
    // redirect the user to the $loginUrl, you can place a button if you want
  
}
$user_profile = $facebook->api('/me');
var_dump($user_profile);   
exit;

Tuesday, February 14, 2012

Change default Shell to Bash in Ubuntu

1. Edit /etc/passwd and find the user whose shell you want to change and replace
/bin/sh to /bin/bash
2. Login as root and fire the command  chsh -s /bin/bash {username}

Now log out and login as the username

The newbash should appear.