Jump to content

asynch websites with PHP and js


ajetrumpet

Recommended Posts

does anyone have an example of new code that is used this day in age for combining js and PHP to produce dynamic content on a webpage?  I have looked at this from w3schools:

https://www.w3schools.com/php/php_ajax_database.asp

but I believe that XMLHttpRequest is really old.  If I rememeber my reading right, it was replaced by fetch() a long time ago.  I think i understand everything that is on that tutorial page, but I would love to see a video tutorial on this subject.  can anyone here point me to such a resource?

Edited by ajetrumpet
Link to comment
Share on other sites

XMLHttpRequest may be old, but it is not going away anytime soon.

The main problem I had was the asynchronous "callback" hell of JavaScript, especially coming from a PHP background. You can not easily return the result of a HTTP request to the calling script. Instead, you have to use a callback function to deal with the response data.

Afaik, fetch makes this easier, since it can wait for a "promise" to be fulfilled (a server responding). I Have not really used it much, but now that I got XMLHttpRequest working with callbacks, I am not planning on changing it. Probably should look into it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.