best way to do cross-site request? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: best way to do cross-site request? (/showthread.php?tid=70196) |
best way to do cross-site request? - richb201 - 03-06-2018 I am in a chrome extension background page. I want to query my CI app, cross-site for some info. What is the best way to do this? XMLHttpRequest? $.post? some other way? I tried using $.post("http://localhost/subit_backend/login_daemon.php","action=login", processResponse); but the "$" is not found. RE: best way to do cross-site request? - albertleao - 03-06-2018 Are you sure you've loaded jquery? RE: best way to do cross-site request? - InsiteFX - 03-06-2018 This article may help you: Cross-Origin Resource Sharing (CORS) RE: best way to do cross-site request? - richb201 - 03-06-2018 (03-06-2018, 07:29 AM)albertleao Wrote: Are you sure you've loaded jquery? Actually I am not! The main part of the Extension uses jquery. Here is the top of my html file <script type="text/javascript" src="jquery-1.11.1.min.js"></script> <script type="text/javascript" src="jquery-ui-1.11.1.min.js"></script> <script type="text/javascript" src="jquery.appendGrid-1.6.3.js"></script> <script src="popup.js"></script> <script src="background.js"></script> <script type="text/javascript" src="date.js"></script> And background.js is the file where the $.post appears. RE: best way to do cross-site request? - dave friend - 03-06-2018 (03-06-2018, 08:50 AM)Muthusamy Wrote: @richb201 According to my point of view $.post is a valid JQuery function. Whereas Code: $_POST("http://localhost/subit_backend/login_daemon.php","action=login", processResponse) RE: best way to do cross-site request? - richb201 - 03-07-2018 I am still at getting the token. When I run the code below I get a whole slew of fields about myself in response. response= "{ "id": "1109308060260095483xx", "email": "[email protected]", "verified_email": true, "name": "Richard Berns", "given_name": "Richard", "family_name": "Berns", "link": "https://plus.google.com/1109308060260095483xx", "picture": "https://lh4.googleusercontent.com/-tzUZ4ZmxxJM/AAAAAAAAAAI/AAAAAAAAAAA/HDERazJjQtE/photo.jpg", "gender": "male" } " var x = new XMLHttpRequest(); x.addEventListener("load",reqListener); //this callabck means we got the email x.open('GET', 'https://www.googleapis.com/oauth2/v2/userinfo?alt=json&access_token=' + token); x.send(); function reqListener(){ console.log(this.response["email"]); } But I only need the response.email field. I will use this as the key that I send to my CI daemon. How do I access the email field in response? My plan is to build a new XMLHttpRequest() to go over to the CI daemen directly in reqListener(). Any pros or cons? |