I've written a function to call a local API using POST:
我编写了一个使用POST调用本地API的函数:
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弹出窗口的响应时,无法将数据发送到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} **
**在这两种情况下,console.log()都返回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.
在Bellow中,您可以看到控制台输出,其中第一个请求(由alertify启动)被重定向,并且没有POST到API。第二个(由.click()启动)将数据发送到API。
1 个解决方案
#1
0
Somehow calling the function first outside alertify cleared this error... strange.
不知怎的,首先在alertify之外调用函数清除了这个错误...奇怪。
#1
0
Somehow calling the function first outside alertify cleared this error... strange.
不知怎的,首先在alertify之外调用函数清除了这个错误...奇怪。