AJAX is not working for me (web service)

Discussion and feedback on Construct 2

Post » Wed Sep 02, 2015 5:17 pm

Hello!

I've been trying to make a very small example work by using
GET parameters with this web service for testing purposes:

http://free-web-services.com/web-servic ... ature.html

I have a small example that uses Ajax to make a request to that URL passing its "temp" and "scale"
parameters but nothing is being returned. Progress code is always 0.

I have setup a small project here to test. Note that the text "Resultado" should be changed to
AJAX.LastData using the On Completed condition.

http://www.byondisoft.com/teste-webservice/

Image

Am I doing something wrong?
Thank you.
B
48
S
14
Posts: 111
Reputation: 3,959

Post » Wed Sep 02, 2015 6:53 pm

I see you use single qoutes in the url, those will not work.

make sure the results of your data url looks like something as:

site.com?option=something&scale=1


and not like

site.com?option='something'&scale='1'



Just remove the single qoutes stuff :)

Also, it might be a good idea to give your request a tag, and use that tag with the on completed trigger too.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Wed Sep 02, 2015 7:30 pm

@lennaert: I tried using single quotes because of this tutorial but I also tried without any quotes before:
https://www.scirra.com/tutorials/525/si ... l-database

I was using a tag before too and you're definitely right in your advices.
But I tried almost any way imaginable and they didn't work.

Thanks for the help.
B
48
S
14
Posts: 111
Reputation: 3,959

Post » Thu Sep 03, 2015 3:02 am

Is the textbox big enough for the reply ?

Also, you can hit F12 or CTRL+SHIFT+J for the console, and perhaps check the network tab, and filter for your url,
If you then click on your url in that pane you get a few tabs with your request with information regarding headers and reply.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Thu Sep 03, 2015 1:40 pm

@lennaert: Thank you for all your support so far.
Debugging in Chrome shows me the error:

XMLHttpRequest cannot load https://php.radford.edu/~jcdavis/D2L/cl ... 23&scale=C. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.byondisoft.com' is therefore not allowed access.


Even if I send the header as "Access-Control-Allow-Origin: *" as in the documentation, the error is displayed.
And then I receive this warning:

Uncaught (in promise) DOMException: Only secure origins are allowed (see: https://goo.gl/Y0ZkNV).


It's either something fundamental that I need to learn about web services and browser security overall or Chrome is being more restrictive than others. Strange thing is that web service is to be tested publicly.

Maybe it's the HTTPS protocol that it uses?

Thanks a lot!
B
48
S
14
Posts: 111
Reputation: 3,959

Post » Thu Sep 03, 2015 3:31 pm

Add this to the top of your PHP file:

header('Access-Control-Allow-Origin: *');
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Thu Sep 03, 2015 11:29 pm

@lennaert: That web service is not mine.
It's publicly available for developers to use and test.
I found it in this list:
http://free-web-services.com/

The one I tried to access is this one:
http://free-web-services.com/web-servic ... ature.html

Maybe it's the web service that doesn't allow this which is strange since it's available
for everyone to use freely.

Thank you for the advices and for the help!
B
48
S
14
Posts: 111
Reputation: 3,959

Post » Fri Sep 04, 2015 8:42 am

Ah, yes, then it will not be possible right from the bat.

The work around:

Use pode's html Iframe plugin, and add the iframe to your project.
Whenever you need to load the info from that URL, load it through the url of the iframe.
either use the iframe as a results box, or, grab the content from the iframe after loading and place it where needed.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Fri Sep 04, 2015 9:28 am

Message: kelbiiz is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
You can go here for reference :
B
3
Posts: 27
Reputation: 217

Post » Fri Sep 04, 2015 2:44 pm

@lennaert: That is a great tip.
I could have that outside the screen and work the values from there.

Thanks a lot. :-)
B
48
S
14
Posts: 111
Reputation: 3,959


Return to Construct 2 General

Who is online

Users browsing this forum: Yahoo [Bot] and 11 guests