I am working on this seemingly trivial problem since three days and ran completely out of ideas why my code doesn't work.
In a nutshell, when the user receives a facebook request and clicks on it, it should be process the invitation.
FB.Event.subscribe('auth.authResponseChange', function (response) {
if (response.status === 'connected') {
if (window.location.href.indexOf('app_invite') !== -1 || window.location.href.indexOf('app_request') !== -1) {
var inviteeID = response.authResponse.userID;
processIncomingInvitation(inviteeID);
}
});
The problem occurs in the following function. Upon the successful $.post()
request I am expecting a simple redirect:
$.post(url, function (result) {
window.location.replace('/True?fbapp=fbapp');
});
But the redirect is ignored and I don't understand why. I even put an alert('hello');
in there instead and I can clearly see it is hitting that bit of code. Why is the redirect ignored instead?
function processIncomingInvitation(inviteeID) {
var urlParams = {};
(function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) {
return decodeURIComponent(s.replace(pl, " "));
},
query = window.location.search.substring(1);
while (match = search.exec(query)) {
urlParams[decode(match[1])] = decode(match[2]);
}
})();
var requestType = urlParams.app_request_type;
if (requestType === "user_to_user") {
var reqIDlist = urlParams.request_ids.split(',');
var requestID = reqIDlist[0];
FB.api(requestID, function (response) {
if (response.from !== undefined && response.from !== 'undefined') {
var inviterID = response.from.id;
var inviterName = response.from.name.split(" ")[0];
var url = '/friend/' + inviteeID + '/accept/' + inviterID + '/?fbapp=fbapp';
$.post(url, function (result) {
window.location.replace('/True?fbapp=fbapp');
});
deleteRequest(requestID);
}
});
}
}