George Chumburidze
George Chumburidze

Reputation: 73

Can't call ajax POST request inside FB.api

For Facebook login I'm using this code

FB.api('/me', {fields: 'birthday,cover,devices,email,first_name,gender,id,last_name,link,location,name,name_format,timezone,verified,website,locale'}, function(response) {


                $.ajax({
                         url: '/login/facebook',
                         type: 'POST',
                         data: { fb: response, window: window.ui},
                         dataType: 'json',
                         success: function (data) {
                             console.log(data); 
                         },

                         error: function (xhr, ajaxOptions, thrownError){
                             notice(xhr);
                             notice(ajaxOptions);
                         }
                });

            });

If i'm calling without {fields: '...'} its working but when added fields ajax sending GET request to server instead of post, how to get response with desired fields from FB.API and post it to server?

Upvotes: 1

Views: 886

Answers (2)

George Chumburidze
George Chumburidze

Reputation: 73

I fixed this problem with little change in code instead of url: '/login/facebook', I wrote url: '/login/facebook/', just / at the end and problem solved !

Upvotes: 1

redsd
redsd

Reputation: 101

Did you try?

FB.api('/me', 'post', {fields: 'birthday,cover,devices,email,first_name,gender,id,last_name,link,location,name,name_format,timezone,verified,website,locale'}, function(response) {
            $.ajax({
                     url: '/login/facebook',
                     type: 'POST',
                     data: { fb: response, window: window.ui},
                     dataType: 'json',
                     success: function (data) {
                         console.log(data); 
                     },

                     error: function (xhr, ajaxOptions, thrownError){
                         notice(xhr);
                         notice(ajaxOptions);
                     }
            });

        });

Upvotes: 0

Related Questions