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!");
             }
            });

Recommended Answers

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 : …
Jump to Post

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

Jump to Post

All 6 Replies

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

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 learning and sharing knowledge.