0

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.

2 Answers 2

1

Resolved:

I need to use:

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

Sign up to request clarification or add additional context in comments.

Comments

0

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?

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.