Welcome Guest, Not a member yet? Register   Sign In
best way to do cross-site request?
#1

(This post was last modified: 03-06-2018, 06:56 AM by richb201.)

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.
proof that an old dog can learn new tricks
Reply
#2

Are you sure you've loaded jquery?
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#3

This article may help you:

Cross-Origin Resource Sharing (CORS)
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(This post was last modified: 03-06-2018, 07:55 AM by richb201.)

(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.
proof that an old dog can learn new tricks
Reply
#5

(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.
Reply
#6

(This post was last modified: 03-07-2018, 01:05 PM by richb201.)

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?
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB