CodeIgniter Forums

Full Version: best way to do cross-site request?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
Are you sure you've loaded jquery?
This article may help you:

Cross-Origin Resource Sharing (CORS)
(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.
(03-06-2018, 08:50 AM)Muthusamy Wrote: [ -> ]@richb201 According to my point of view
Code:
$.post("http://localhost/subit_backend/login_daemon.php","action=login", processResponse)      this is wrong
You have to mentioned as $_POST
Code:
$_POST("http://localhost/subit_backend/login_daemon.php","action=login", processResponse)

$.post is a valid JQuery function.

Whereas
Code:
$_POST("http://localhost/subit_backend/login_daemon.php","action=login", processResponse)
is complete nonsense. $_POST is an array, not a function that accepts arguments.
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?