How do I obtain last data with Ajax Object in local ?

Just started using Construct 2? Post your questions here

Post » Sat Mar 15, 2014 9:55 pm

Hello,
I'm new with Construct 2 and i try to use Ajax Object on my project. Sorry if my english is bad, I'm french :D .
I have follow this tutorial : and i have problem when i would print data from my Ajax Request. I'm working on local network.

I have created a Sprite and when i click on it, i launch Ajax Request to get data from a file. My Ajax request completes successfully but I can't recover the data. I tried to display the data in a field "Text" with AJAX.LastData property but nothing appears. By changing the field "Text" with an arbitrary value, the change is made ​​when the Ajax request completes.

I activated the Access-Control-Origin on my browser. If I get the address of the file directly in my browser, the text is displayed correctly.
My file contain : "I'm a test file" but nothing is displayed on "Text" Field.

Have you an idea of what can block?
Thank you in advance,
B
2
Posts: 4
Reputation: 158

Post » Sun Mar 16, 2014 10:40 am

When the AJAX Object has no Data, I guess the request was not successful.
Which browser are you using? Maybe you can open developper tools (F12 in every browser, in FF you need to install FireBug) and see if the request was successfull.
B
14
S
3
G
1
Posts: 255
Reputation: 2,027

Post » Sun Mar 16, 2014 11:57 am

Hello,
I'm using Firefox and i have installed Firebug. I attach a screenshoot of my request.
When I entered the address into my browser: I get well "I'm a test file."
When I look at the response tab of Firebug, it is empty despite a response "200 OK" visible on screenshoot.

Someone should track?
Thank you in advance
You do not have the required permissions to view the files attached to this post.
B
2
Posts: 4
Reputation: 158

Post » Sun Mar 16, 2014 12:47 pm

Do you use Ajax request or Ajax post?
Is the file in localhost/construct/ajaxExampleGet.php?
What does ajaxExampleGet.php do?
B
14
S
3
G
1
Posts: 255
Reputation: 2,027

Post » Sun Mar 16, 2014 1:00 pm

Hello I'm using Ajax Request not Ajax post.
The file is in localhost/construct/ajaxExampleGet.php and i can access to him by enter the adress in my browser.
ajaxexampleGet.php only display a message. There are not yet php just text.
B
2
Posts: 4
Reputation: 158

Post » Sun Mar 16, 2014 2:54 pm

May I see your c2 code?

And try to make an AJAX request to a random site (like google.com) and see if this is working.
B
14
S
3
G
1
Posts: 255
Reputation: 2,027

Post » Sun Mar 16, 2014 3:16 pm

I have the same problem with an adress like google.com. The response is empty. I don't see what can blocking request.

My c2 code is in attachment.
Thanks for your help.
You do not have the required permissions to view the files attached to this post.
B
2
Posts: 4
Reputation: 158

Post » Sun Mar 16, 2014 5:23 pm

There must be something wrong with your localhost.
When I type in this adress: http://ip.jsontest.com/ its working.
You response also has to be a string as far as I know.
B
14
S
3
G
1
Posts: 255
Reputation: 2,027


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests