php - Retriev variable values in javascript function -


i using facebook api project , getting data in following manner in var mydata

if (response.status === "connected")         {             lodinganimate(); //animate login             fb.api('/me?fields=movies,email', function(mydata) { //--             console.log(mydata);               if(data.email == null)               {                  alert("you must allow access email id!");                  resetanimate();              }    } 

i dont have issue code. want send data using ajax call process , insert database.

my ajax call:

function ajaxresponse()  {     var send=document.ge(mydata)      **//here want fetch mydata previous code**     var datas = document.elements['id'].value;     var s = 'connect=1';       $.ajax({     type: "post",     url: "process_facebook.php",     data: s,send                   **//is correct way send s , send togather? have tried 's' works fine dont know both togather**     }).done(function(result) {     $("#fb-root").html(result);     });    } 

can please assist how fetch mydata in javascript function , review code.

since facebook api call you're making asynchronous, can't return value ge function.

instead, use callback, facebook , else does. see below.

separately, answer second unrelated question hidden in code snippet "no, that's not how that". i've given pointer how below well.

function ajaxresponse() {     // callback here----v arg ---v     document.ge(mydata, function(send) {         var datas = document.elements['id'].value;         $.ajax({             type: "post",             url: "process_facebook.php",             data: {                connect: 1,                paramname: mydata      // <=== don't know name of param             }         }).done(function(result) {         $("#fb-root").html(result);     }); } 

..and have code call callback when facebook call calls its callback.

function ge(data, callback) {     // ...     if (response.status === "connected") {         lodinganimate(); //animate login         fb.api('/me?fields=movies,email', function (mydata) { //--             console.log(mydata);             if (data.email == null) {                 alert("you must allow access email id!");                 resetanimate();             }             else {                 callback(data); // <=== trigger callback             }         }        // ...     }     // ... } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -