How to do AJAX in WordPress correctly (2023)

  Рет қаралды 4,517

Alejandro AO - Software & Ai

Alejandro AO - Software & Ai

Күн бұрын

WordPress has its own way of implementing AJAX calls. In this video, we will explain as clearly as possible how to do AJAX requests in WordPress. I am considering that you are somewhat familiar with Javascript and PHP.
This video is divided into two sections. The first one explains what an AJAX call is. The second one is the step-by-step instructions for WordPress.
TLDR: If all you need are the JS and PHP code snippets for your request, here they are:
👉 / how-to-do-ajax-in-word...
AJAX is a technique that appeared in the late 1990s and early 2000s. The real revolutionary thing about it is that it used current technologies to do something extremely powerful and new: updating the content of your website without reloading the page.
Until then, if you wanted to update a simple button or the elements in your inbox, you would’ve needed to refresh the entire page. But reloading an entire page for only a single element is not very resource-effective.
What AJAX allows us to do is to update a particular part of your website with information from your server without refreshing the entire website.
------------------------------------------------------------------------------------------------------------------------------
🕒 Timestamps:
0:00 Introduction
2:22 What is AJAX
8:16 AJAX in WordPress
10:47 Set up your trigger
13:47 Set up your request
20:10 Handle your request
29:34 Axios and common errors
33:10 Conclusion

Пікірлер: 21
@arifmmdv4612
@arifmmdv4612 Жыл бұрын
cool video
@alejandro_ao
@alejandro_ao Жыл бұрын
i appreciate it
@manuellehenberger8673
@manuellehenberger8673 Жыл бұрын
well done video. You should mention sanitation of the data you send to wordpress backend.
@alejandro_ao
@alejandro_ao Жыл бұрын
good call, thank you! yes, indeed, it is a good practice to manually sanitize the data you send to the backend before doing anything with it. here is a very good video that explains this in more detail : kzfaq.info/get/bejne/bdZph7qg1tzRoGg.html
@jeshuavega8270
@jeshuavega8270 Жыл бұрын
Hey Alejandro, great video. Do you speak spanish by any chance? Look, I have an AJAX request that triggers every 2 seconds with setTimeout() this is for a live data feature that must be implemented. But I wonder if there is a way to only make the request or fetch the content/data when actually the content has changed and not every time without changes. This would help to avoid unnecessary request and save server resources. I've read some "If-Modified-Since" HTTP header but nothing conclusive.
@patrickmuller9819
@patrickmuller9819 2 ай бұрын
how would I trigger the request from a hook (add_filter) in a wordpress functions.php oder plugin file instead of a button?
@alejandro_ao
@alejandro_ao Жыл бұрын
hey please help me get to 1k subs :)
@dayeshrp6610
@dayeshrp6610 Жыл бұрын
Hey I found you on Reddit.
@alejandro_ao
@alejandro_ao Жыл бұрын
wohooo welcome onboard my friend 🔥
@babarburrak4519
@babarburrak4519 Жыл бұрын
Hmm bring complete tutorial about theme building.
@alejandro_ao
@alejandro_ao Жыл бұрын
hey, sure i did one like that: Convert HTML template to WordPress Theme (2023) - Full Course kzfaq.info/get/bejne/d5uia86k0bS3dmQ.html
@HaifengZhu-pn3uq
@HaifengZhu-pn3uq 10 ай бұрын
hi, apart from html, css, js and php, what other codes will be used in wordpress development?
@alejandro_ao
@alejandro_ao 10 ай бұрын
hey there. i would say that’s all. you may also need SQL to interact with the database though
@creativityoutside
@creativityoutside 5 ай бұрын
Hello Alejandro! Greate turorial. But what about wp_localize_script, I don't see you using it here? Why?
@alejandro_ao
@alejandro_ao 5 ай бұрын
hello there, you can also use this function if you want to make certain data available to your javascript from the start. for example, you would pass a PHP object named $object in the wp_localize_script() function and it will be available in your javascript app as the variable `object`. in this video i go for a more modern approach, where the front-end app (javascript) makes a request to the back-end (PHP) and gets data as response. you can use whichever you are more comfortable with!
@creativityoutside
@creativityoutside 5 ай бұрын
Thank you@@alejandro_ao for quick reply. Well, so requesting from front-end to back-end directly is modern approach? Should I drop using wp_localize_script()? in my from along with other validation I need to check unique email.
@LoadOfJak
@LoadOfJak 5 ай бұрын
@@alejandro_ao Is there any benefit in using ajax-admin over the REST or rewrite API for making these kind of requests?
@petruciucur
@petruciucur 6 ай бұрын
totally borring... to me... You need to go straight into action and exemplify by coding various scenarios from reality
@alejandro_ao
@alejandro_ao 5 ай бұрын
good point 📝 thanks!
@petruciucur
@petruciucur 5 ай бұрын
@@alejandro_ao I didn't mean to be mean, clearly I was. Sorry!
@alejandro_ao
@alejandro_ao 5 ай бұрын
@@petruciucur no worries! i appreciate constructive feedback. but take a look at newer content, i've become better at this!
Import a MySQL database to WordPress (no plugin)
18:14
Alejandro AO - Software & Ai
Рет қаралды 3 М.
3 Methods for AJAX in WordPress | Which Method is the Best?
23:09
Did you believe it was real? #tiktok
00:25
Анастасия Тарасова
Рет қаралды 55 МЛН
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 105 МЛН
Was ist im Eis versteckt? 🧊 Coole Winter-Gadgets von Amazon
00:37
SMOL German
Рет қаралды 39 МЛН
Incredible magic 🤯✨
00:53
America's Got Talent
Рет қаралды 75 МЛН
How to Build Dynamic (PHP) Blocks in WordPress
30:57
Brian Coords - WordPress Dev
Рет қаралды 8 М.
PHP on the frontend! No more Javascript!
14:47
Aaron Francis
Рет қаралды 119 М.
UI Libraries Are Dying, Here's Why
13:28
Theo - t3․gg
Рет қаралды 280 М.
Form Submit Using Ajax - WordPress Form Ajax
1:09:25
Joshua Herbison
Рет қаралды 18 М.
Wordpress vs coding - why devs SHOULD learn Wordpress
11:03
SuperSimpleDev
Рет қаралды 287 М.
Configure Webpack 5 in Wordpress (2023) with Typescript and SASS
58:23
Alejandro AO - Software & Ai
Рет қаралды 4,3 М.
Did you believe it was real? #tiktok
00:25
Анастасия Тарасова
Рет қаралды 55 МЛН