I’ve written a function to call a local API using POST:
function setOpenGraph(setValue) {
requestData = {
user : $.user._id,
opengraph : setValue
};
console.log(requestData);
$.ajax({
type: 'POST',
data: requestData,
dataType : 'json',
url: '/api:setopengraph',
success: function (data) {
$.user.opengraph = setValue;
console.log(data);
}
});
}
This works when called on a click event for a link on the page. However when I call it as a response to an alertify popup is fails to POST the data to the api:
alertify.set({ labels: { ok: "ON", cancel: "OFF" } });
alertify.confirm( 'message here', function (e) {
if (e) {
$(".toggleopengraph").html('turn facebook sharing off');
setOpenGraph(true);
} else {
$(".toggleopengraph").html('turn facebook sharing on');
setOpenGraph(false);
}
});
**In both cases console.log() returns Object {user: “XXXXXXXXXXXXXX”, opengraph: false} **
Bellow you can see the console output where the first request (Initiated by alertify) is redirected and does not POST to the API. The second (Initiated by .click()) POSTS the data to the API.

Somehow calling the function first outside alertify cleared this error… strange.