我需要从我的AJAX到我的fb共享对话框获得响应[' cloudUrl'],所有这些都发生在用户点击#sharebutton的同时。
我无法将我的代码放入AJAX成功,如果我将其包装在除用户点击事件之外的其他内容中,浏览器最有可能阻止我的fb共享弹出窗口。
为了让事情更清楚,我可以在AJAX成功回调中得到回复[' cloudUrl']。
function submitDataToFbShare(){
$.ajax(
{
url : 'www.testing.com/fb-data")',
type : 'POST',
data :
{
name: $('.nameField').val(),
personality_index: $('.nameField').val(),
country: $( "#countryList select:first-child option:selected").attr("value"),
},
dataType:'json',
success : function(response)
{
console.log("Successfully saved!");
console.log("response " + response['cloudUrl']);
},
error : function(request,error)
{
console.log("Error saving data!");
}
});
}
$('#sharebutton').click(function(e){
submitDataToFbShare();
e.preventDefault();
FB.ui({
method: 'feed',
link: "www.test.com",
name: "test",
description: "testing description",
picture: response['cloudUrl'],
}, function(response)
{
if (response != null || response != undefined)
{
console.log("success");
}
else
{
console.log("failed");
}
});
});