Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I am trying to send data from function to ajax call using callback function.

I have function:

function CallAfterLogin(data,callback){
        FB.login(function(response) {  //---
        if (response.status === "connected")
        {
            LodingAnimate(); 
            FB.api('/me?fields=movies,email', function(mydata) {
            console.log(mydata);
              if(mydata.email == null)
              {
                 alert("You must allow us to access your email id!");
                 ResetAnimate();
              }else {
                alert("hi");
                callback(data); // <=== Trigger the callback
            }
              }); //--
         } //if
             }); //---

Which I am calling on button click event:

<button type="button" onclick="CallAfterLogin()" ?>Click Me!</button>

I want to send data to ajaxResponse() function:

function AjaxResponse()
 {
    document.CallAfterLogin(mydata, function(send) {
        var myData = 'connect=1'; 
        $.ajax({
        type: "POST",
        url: "process_facebook.php",
        data: {
                   connect: 1,
                   myd: mydata      //
                  }
                  }).done(function(result) {
                        $("#fb-root").html(result);
                     });
               });
  } 

Above code works till callback(data); // <=== Trigger the callback and then in Firebug I could not see any error or warning. It shows profiler is running for few seconds and then no activity.

I think there's issue after call to callback(data); Can someone give me what is the issue here? I tried to call ajaxResponse() function on buttonclick event but it makes no action.

share|improve this question

Resolved:

I need to use:

<button type="button" onclick="AjaxResponse()" ?>Click Me!</button>

share|improve this answer

Does firebug show the "hi" text being written to the console? Where is the code for the 'callback(data)' function? Did you mean to call the 'CallAfterLogin' function at that point?

share|improve this answer
    
Yes, "Hi" get prompted. I think I dont need to code callback as per tutotials I show for callback function. I mean to call ajaxResponse somehow and get data there. – user123 Aug 12 '13 at 4:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.