title: Pass JavaScript value to PHP using JQUERY Ajax (Values are from Facebook Javascript SDK)
body: <p>First of all, I would like to thank you for the time you spend to read my post.</p>
  
  <p>I am trying to add Facebook Javascript SDK to a web page and when user logged in, the user data will be saved into mysql using php.</p>
  
  <p>I almost can kind of figure it out how to insert PHP variable data in MYSQL but as this is first time I'm using Javascript language then I am total new :(</p>
  
  <p>To make the story short what I am really looking forward is that someone kindly show me in a simple webpage following things:</p>
  
  <p>1- Webpage starts and checks if the user had been logged into Facebook and also if the user logged into the app (gave permission to the app to have access to the user basic profile info and Email)</p>
  
  <p>2- If the user is not logged into Facebook user will be redirected to the Facebook login page or if user did not give permission to the App yet, it is asking for the necessary permissions.</p>
  
  <p>3- If the user passed the first two stages(user successfully connected), the page will display the following message "<strong>Hello dear $User_Facebook_Name</strong>".</p>
  
  <p><strong>$User_Facebook_Name</strong> is a PHP Variable passed by Javascript from Facebook Javascript SDK</p>
  
  <p>I would like not to use Submit button to pass the Javascript variables to PHP (The website page doesn't refresh).</p>
  
  <p>I prefer to use Facebook Javascript SDK, PHP, Jquery(Ajax) for this issue.</p>
  
  <p>So far I have the following codes and the page displays the message but using Facebook Javascript SDK like this :</p>
  
  <p>FB.api(uid, function(info) {</p>
  
  <p>$('#welcome').html("Hello dear " + info.name );</p>
  
  <p><strong>index.php</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
  
    &lt;script type="text/javascript" src="js/jquery-1.11.1.min.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="js/myscript.js"&gt;&lt;/script&gt;
    
  &lt;/head&gt;
    
  &lt;body&gt;
    
    &lt;div id="fb-root"&gt;&lt;/div&gt;
    
    Hello dear &lt;?php&gt; echo "$user_Facebook_Name"; ?&gt;
    
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>myscript.js</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>      window.fbAsyncInit = function() {
          FB.init({
            appId      : 'App_ID',
            xfbml      : true,
            version    : 'v2.1'
          });
   
   
   
   //Next, find out if the user is logged in
     
   FB.getLoginStatus(function(response) {
  
    if (response.status === 'connected') {
      // the user is logged in and has authenticated your
  
      var uid = response.authResponse.userID;
      var accessToken = response.authResponse.accessToken;
   
   
   FB.api(uid, function(info) {
      
   $('#welcome').html("Hello dear " + info.name );
   
        });
   
   
   
    } else if (response.status === 'not_authorized') {
      // the user is logged into Facebook, 
      // but has not authenticated your app
   
   var oauth_url = 'https://www.facebook.com/dialog/oauth/';
        oauth_url += '?client_id=App_ID'; //Your Client ID
        oauth_url += '&amp;redirect_uri=' + 'http://website.com/'; //Send them here if they're not logged in
        oauth_url += '&amp;scope=email,user_friends';
  
        window.top.location = oauth_url;
   
   
   
   
   
    } else {
      // the user isn't logged in to Facebook.
   
    }  //Response.status
   }); // Get login status  
  }; //FB Async
     
  
  
     
     
  // Load the JavaScript SDK Asynchronously
        (function(d, s, id){
           var js, fjs = d.getElementsByTagName(s)[0];
           if (d.getElementById(id)) {return;}
           js = d.createElement(s); js.id = id;
           js.src = "//connect.facebook.net/en_US/sdk.js";
           fjs.parentNode.insertBefore(js, fjs);
         }(document, 'script', 'facebook-jssdk'));
      
      </code></pre>
  </div>
  </div>
  </p>
  
  <p>Any help would be really appreciated and would like to thank you in advance.</p>