Possible to stop redirect after submitting POST request to Facebook graph? -


quick background: i've created basic facebook app users can "like" post website outside of facebook. users authenticate, redirected access_token gathered js , inserted form via hidden field , passed post request. (not relevant, use js automatically submit 'like' after user redirected site facebook.)

after http request sent (and successful), user redirected response page, rendering "true" printed on screen. there way stop redirect? i've set js swap out div content once form submitted, can't seem stop them being directed away.

thanks in advance ideas.

html excerpt

    <!-- *authentication section* -->     <div id="submit_like">       <form>        <a id="facebook-authentication" href="https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=[my_app_id]&redirect_uri=[my_post-authorization_redirect_url]&scope=offline_access,publish_stream">        <div id="facebook-authentication-button">        start vote!        </div>        </a>       </form>     </div>  <!-- after authentication, form submitted --> <form id="likeform" method="post" action="https://graph.facebook.com/[facebook_id]/likes"  >   <input id="authcode" name="access_token" type="hidden" value="123"> </form> 

you can use jquery .post() method submit form without page redirection. in case:

$.post("https://graph.facebook.com/[facebook_id]/likes", $("#likeform").serialize()).done(function(data){      // redirect new page or nothing stay put.     alert(data); //show returned value  }); 

the .serialize() helper function takes form input , creates string in url-encoded notation. string sent parameter, contain access_token hidden form input.

just reminder, sure have jquery included.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script> 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -