Я делаю услугу, которая при нажатии сохраняет информацию пользователя пользователя в базе данных Facebook. Теперь проблема в том, что мои услуги вызывают дважды. Я не могу понять, почему он ведет себя таким образом. Пожалуйста помоги.функция java-script называется дважды
Index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="css/jquery.jgrowl.min.css">
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/jquery.validate.min.js"></script>
<script type="text/javascript" src="scripts/jquery.blockUI.js"></script>
<script type="text/javascript" src="scripts/jquery.jgrowl.min.js"></script>
<script type="text/javascript" src="scripts/fb.js"></script>
</head>
<body>
<div id="fb-root"></div>
<table align="center">
<tr>
<th>Registration Method</th>
</tr>
<tr>
<th><input type="button" value="Login With Facebook" id="fb-auth"> </th>
</tr>
</table>
</body>
</html>
fb.js
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxxxxxxxxxx',
xfbml : true,
version : 'v2.1',
status : true,
cookie : true,
oauth : true
});
function updateButton(response) {
var button = document.getElementById('fb-auth');
if (response.authResponse) { // in case if we are logged in
var userInfo = document.getElementById('user-info');
FB.api('/me', function(response) {
var socialMediaRegistration={};
socialMediaRegistration['name']=response.name;
socialMediaRegistration['profileId']=response.id;
socialMediaRegistration['email']=response.email;
socialMediaRegistration['socialPlatform']="Facebook";
var mydata={};
mydata['socialMediaRegistration']=socialMediaRegistration;
submitData(mydata);
});
button.onclick = function() {
FB.logout(function(response) {
window.location.reload();
});
};
} else { // otherwise - dispay login button
button.onclick = function() {
FB.login(function(response) {
if (response.authResponse) {
window.location.reload();
}
}, {scope:'email,public_profile'});
}
}
}
// run once with current status and whenever the status changes
FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.statusChange', updateButton);
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "http://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + 'http://connect.facebook.net/en_US/all.js';
if (document.getElementById('fb-root'))
{document.getElementById('fb-root').appendChild(e);};
}());
function submitData(data){
alert("this is below the submitdata");
alert(JSON.stringify(data));
$.support.cors = true;
$.jGrowl.defaults.position = 'center';
$.ajax({
type: "POST",
url: "http://localhost:8080/components/services/saveSocialMedia",//use ur service
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
crossDomain: true,
dataType: "json",
success: function (data, status, jqXHR) {
$.unblockUI();
$.blockUI({ message: null });
$.jGrowl('Application Reference: '+data["Id"]+' is created. <br/><br/>Have a nice day!', {
sticky: true,
header: 'Request Submitted Successfully!',
life: 5000,
speed: 'slow',
animateOpen: {
height: "show",
width: "show"
},
animateClose: {
height: "hide",
width: "show"
},
close: function(e,m,o) {
$.unblockUI();
//$("#ApplicationRequestForm")[0].reset();
},
click: function(msg) {
$.unblockUI();
//$("#ApplicationRequestForm")[0].reset();
$("div.jGrowl").jGrowl("close");
return true;
}
});
},
error: function (jqXHR, status) {
$.unblockUI();
$.blockUI({ message: null });
$.jGrowl('Please try again after sometime.', {
sticky: true,
header: 'Ouch! An Unexptected Error Occurred.',
life: 5000,
speed: 'slow',
animateOpen: {
height: "show",
width: "show"
},
animateClose: {
height: "hide",
width: "show"
},
close: function(e,m,o) {
$.unblockUI();
},
click: function(msg) {
$.unblockUI();
$("div.jGrowl").jGrowl("close");
return true;
}
});
console.log(jqXHR);
}
});
}