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?


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
$.post("http://localhost/subit_backend/login_daemon.php","action=login", processResponse)      this is wrong
You have to mentioned as $_POST
$_POST("http://localhost/subit_backend/login_daemon.php","action=login", processResponse)

$.post is a valid JQuery function.

$_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.

"id": "1109308060260095483xx",
"email": "[email protected]",
"verified_email": true,
"name": "Richard Berns",
"given_name": "Richard",
"family_name": "Berns",
"link": "",
"picture": "",
"gender": "male"

        var x = new XMLHttpRequest();
          x.addEventListener("load",reqListener);   //this callabck means we got the email
'GET', '' + token);

function reqListener(){

But I only need the 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?