function cbfunc(o){ var token = o.api_token; if(token == undefined){ $('#error').html('Identification erronnée'); }else{ $.post('ajax/saveTodoist.php', {token: token}, function(data){ $('body').append('Etape suivante'); if(data=="ok"){ location.reload(); }else{ alert(data); } }); } } $(document).ready(function(){ $('#loginBtn').click(function(){ var email = $('#email').val(); var password = $('#password').val(); var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://todoist.com/API/login?email='+email+'&password='+password+'&format=json&callback=cbfunc'; document.getElementsByTagName('head')[0].appendChild(script); }); });