How do I get the userid using AJAX

Get help using Construct 2

Post » Thu Mar 31, 2016 8:26 pm

Hi,

I have read all the tutorial about AJAX in this site but I still can't figure this out.
I need to get the userid variable from a PHP page.

Here is what I am doing:
Image

Image

HERE is what I am getting
Image

How can I only get the variable and not the whole page?

thanks,
B
117
S
49
G
24
Posts: 401
Reputation: 22,282

Post » Thu Mar 31, 2016 11:06 pm

You should show the PHP script because this is the place where you return data.

Basically you should have something like:

Code: Select all
<?php
$userId = "whatever value you want";
die($userId);
?>


Also you are sending an empty GET variable in your url "?userid" part which is not needed. So cut your URL at the end and echo variable in PHP script and that's it.
ImageImageImage
B
27
S
16
G
74
Posts: 977
Reputation: 41,673

Post » Fri Apr 01, 2016 12:42 am

@BackendFreak,

Your solution works but the problem is that I don't have access to the PHP file. This is kind of an API, I just trying to get the userid from a PHP page using Construct2.

Is there another way to do that?
B
117
S
49
G
24
Posts: 401
Reputation: 22,282

Post » Fri Apr 01, 2016 2:47 am

jogosgratispro wrote:.. the problem is that I don't have access to the PHP file.
Is there another way to do that?

I'm guessing that you'll need to cut out unwanted parts..with tokenat,left,right or regex

e.g
set Text to.........tokenat(AJAX.LastData,0,"<")
will return only usersad64gfa6df4asd6f5454
Image
B
65
S
23
G
7
Posts: 1,505
Reputation: 10,896

Post » Fri Apr 01, 2016 2:57 pm

@korbaach
Yes. It is a good idea but I need to single out the userid only. I am not sure where it is in the code. So I can't index it using the tokenat.

I guess there is no solution for that.
Last edited by jogosgratispro on Fri Apr 01, 2016 4:01 pm, edited 1 time in total.
B
117
S
49
G
24
Posts: 401
Reputation: 22,282

Post » Fri Apr 01, 2016 2:59 pm

What if I use another PHP file to retrieve the userid and then pass it to Construct2?
B
117
S
49
G
24
Posts: 401
Reputation: 22,282


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, Matei511 and 64 guests