How to use a ajax json

I am a newer user of Inventor2.
I had used in other app languaje a call to ajax to execute a php file with parameters that response with json format result. And then I use these data inner the app.
How can I implement this in Inventor2?

You cannot run php through the AI2 webviewer (there is no php server). You will have to use a remote server to do this. More complex javascript such as ajax can struggle to work properly on the webviewer as well (it is not a full browser with all the capabilities of say, Chrome or Firefox. Normal javascript works very well.

1 Like

There is a JavaScript Stunts section in FAQ
AI2 | FAQ
Also see the WebViewer section.

Thank Abraham, I will try to adapt my needs to the code and I will respond by this means to see how it works.
maybe I took a while to do it Well I am new to the use of the inventor app I have to get used to the way of programming by blocks

Hello, I have a problem when I call webfetch, sometimes it works and other gives this error:
The variable $responseCode is not bound in the current context
Note: You will not see another error reported for 5 seconds.

what is wrong?

Please provide a more detailed explanation of what you are trying to achieve,
what you have done so far, what works, what doesn’t work…

Please show your relevant blocks,
if relevant, your data or lists,
screenshots of the Designer screen or app in action,
so we can see what you are trying to do…

Right Click in Blocks Editor and select “Download Blocks as Image”
for the best image of your blocks.

You can't see it outside the event.
Save it in a global variable so you can inspect it later.

It is rare to operate, the first time I press CONTINUE gives error but then no. This happens on screen 2.

I’m attaching the aia for you to see at

www.web-moebius.com/iwiit/local.aia

.

Thanks

You have a “responseCode” block out of context on Screen2 blocks as per the previous post on this

You are not switching screens correctly. Wherever you want to go to Screen1, replace those blocks with “Close Screen”

Use different screens wisely

If you decided to use different screens, then you should switch them correctly, else you will run out of memory after a while...      
The recommended method of switching screens in App Inventor
(Thanks Taifun)
 
Also see demo: multiscreen.aia
 

also follow every one’s advice about Screens.

These days I was reading the examples in this book about JavaSript, Ajax and PHP (Chapter 17, page 395, I put it in this discussion in case it can be interesting.

Learning PHP, MySQL, JavaScript, CSS & HTML5

Thanks!!! I reconfigure my aplication and replace all screens with vertical disposition frames.

the app works faster than the multi-screen version.

You are right. I needed to create a global variable. I thought the mistake was given by fetchweb but actually was the procedure that called fetchweb.

An error persisted which is that the first time I call fetchweb the response code is 0 (instead of 200), and the second time it runs correctly. It seems that fetchweb must be initialized with a query.
I solved it by generating a spurious query. When doing the actual query, since it is already the second, it works correctly.
I still do not know the language to find these subtleties, surely I lack some process of initialization of communication, but for practical purposes this solution worked ok. Thank you for your input. They made my learning curve very fast.

This sounds like the Instant Gratification Bug.

That’s the bug where a programmer expects to see responses instantly
to requests that take time for their responses to arrive, like File I/O
or Web requests.

Such programmers hang around their mailboxes, wasting all day
watching for the mail man, when instead they could be doing something
else more productive, like taking a nap.

1 Like

I tried to play, as quickly as possible, an app that I presented in a project.

That’s why I had to make it work right away.

Now that I finished it I was able to do the tests and corrections to execute with “elegance”.

Thanks, Without your help, it would have taken me a long time to make those ajax calls

Sincerely, Guillermo Drexler