FB.api('/me', function(userInfo) {
            console.log(userInfo.email);
            var emailid = userInfo.email;
            console.log(emailid);


            })

            $.ajax({
             url: 'index.php?r=tryon/saveemailid', 
             type:'post',
             data:{'saveemail':emailid},
             success : function(data){
              alert("success!");
             }
            });

i have store user email in one variable and want to pass it ajax data ?

i face error like Uncaught ReferenceError: emailid is not defined

please reply me.................

Hi,
emailid is declared in FB.api, in this case emailid isn't visible for $.ajax({....})
Declare emailid before FB.api and just set value for this variable in FB.api

var emailid = "";
 FB.api('/me', function(userInfo) {
    console.log(userInfo.email);
    emailid = userInfo.email;
    console.log(emailid);
})
$.ajax({
    url: 'index.php?r=tryon/saveemailid',
    type:'post',
    data:{'saveemail':emailid},
    success : function(data){
        alert("success!");
    }
});
Member Avatar for diafol

Just to add, research 'scope of variables' for more info.

thank you buddy!.................

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.