You will need to actually POST the parameters as data
(in the body of the HTTP request), not append them to the GET parameters in the url. Use
$.post(ref+'api.php?action=login&format=json', {
lgname: login,
lgpassword: pass,
lgtoken: data.login.token,
sessionid: data.login.sessionid,
lgdomain: ref
}, function(data) { … });