Calling Ajax method using javascript function -
i'm working jquery mobile.
my code move details
div ::
<a href="#details" data-ajax="true" data-transition="pop" data-role="button" data-inline="false" data-icon="info">go details</a>
now, want authenticate user facebook.
so have applied ::
<a href="javascript:userlogin()" data-ajax="true" data-transition="pop" data-role="button" data-inline="false" data-icon="info"> login faceook </a>
function calling authentication
function userlogin() { fb.login( function(response) { if (response.authresponse) { alert('logged in'); fb.api('/me', function(response) { alert("welcome " + response.name); }); } else { alert('not logged in'); } }, { scope: "email" } ); }
i'm getting valid user response after authentication.
now want navigate details
div.
so, how can implement ajax code after login ??
any suggestion appreciated.
thanks.
instead of changing href
attribute directly, should bind onclick
event function returning true
.
modify a
tag.
<a href="#details" onclick="javascript:return userlogin()" data-ajax="true" data-transition="pop" data-role="button" data-inline="false" data-icon="info">go details</a>
modify userlogin
function:
function userlogin() { fb.login( function(response) { if (response.authresponse) { alert('logged in'); fb.api('/me', function(response) { alert("welcome " + response.name); }); } else { alert('not logged in'); } }, { scope: "email" } ); return true; }
it seems fb.login
asynchronized operation. if want redirect after login action, try modify location.hash
after login. note return value has changed false
.
function userlogin() { var hash = '#details'; fb.login( function(response) { if (response.authresponse) { alert('logged in'); fb.api('/me', function(response) { alert("welcome " + response.name); window.location.hash = hash; }); } else { alert('not logged in'); } }, { scope: "email" } ); return false; }
Comments
Post a Comment