0
votes

I have a facebook application. The users are logged in and authorized. I am calling fb.api to post the user's name to my textfile. The alert shows the name. The post doesn't seem to post to my aspx file..

FB.Event.subscribe('edge.remove', function (href, widget) {
    alert("outside");
    FB.api('/me', function (response) {
        alert(response.name);
        var paramsObj = { 'name': response.name };
        $.post("ajax/delete.aspx", paramsObj);
    });
    window.location.replace("Default.aspx");
});

I've updated my code to include showing the encapsulating facebook calls to give a broader picture as well as to include @Lix changes [thank you!].

2
Try Firebug and keep an eye on the "Net" tab. - ifaour
tried that... the post is literally not being posted... - Skippy Daniels
1) you don't have to wrap your keys with quotes. 2) try removing the alerts 3) try commenting the window.location.replace(..) - ifaour

2 Answers

0
votes

Few things you might want to try :

  1. Define your post parameters object before and only place the objects name in the jQuery $.post method.
  2. Wrap your json keynames with quotes.

    var paramsObj = { 'name':response.name};
    $.post("ajax/write.aspx", paramsObj );

  3. Use firebug/chrome developers tools to debug the AJAX request and see if any value is being passed and/or use breakpoints in your code to help you understand where the value is missing.

0
votes

The page was being redirected prior to the api call/ajax post. This is what worked:

FB.Event.subscribe('edge.remove', function (href, widget) { 
    FB.api('/me', function (response) { 
        var paramsObj = { 'name': response.name }; 
        $.post("ajax/delete.aspx", paramsObj);
        window.location.replace("Default.aspx"); 
    }); 
});