AJAX is not working for me (web service)

0 favourites
  • 10 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • 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/

    Am I doing something wrong?

    Thank you.

  • 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.

  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • lennaert: Thank you for all your support so far.

    Debugging in Chrome shows me the error:

    [quote:1a7je1xd]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:

    [quote:1a7je1xd]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!

  • Add this to the top of your PHP file:

    header('Access-Control-Allow-Origin: *');

  • 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!

  • 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.

  • You can go here for reference :

  • lennaert: That is a great tip.

    I could have that outside the screen and work the values from there.

    Thanks a lot.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)