Ce libre AJAX JavaScript tutorial vous guide comment construire une application simple en utilisant PHP et AJAX JavaScript Cette libre de HTML JavaScript tutoriel vous fournit des renseignements utiles sur JavaScript et AJAX : Comment fonctionne AJAX, un simple demande Web AJAX (Avec exemple de code JavaScript), AJAX simple demande Code Explication web.
- Demo
- Agrandir
- Recharger
- New window
G�n�rez vos vid�os d'entreprise par l'IA avec la voix ou simplement du texte
Votre premi�re application vid�o AI GRATUITE ! Automatisez votre premi�re vid�o AI. Cr�ez votre vid�o professionnelle en 5 minutes gr�ce � l'IA. Aucun �quipement ni comp�tence en montage vid�o requis. Production vid�o sans effort pour les sp�cialistes du marketing de contenu.
To those of you who are used to my typical crazy picture/funny video/interesting stuff post, you will have to excuse me a few posts to talk about nerdy things. This being one of those posts. Unless you care about programming, stop reading now.
How ajax works
Building the new style web 2.0 sites that contain Ajax functionality is actually quite simple, especially now with the multitude of frameworks being released to simplify this (Atlas, jQuery, etc). But I am a bit old school and like to know exactly what is happening when my code executes as opposed to using pre-built functions and assuming they will work for every scenario I must handle. Sure, these frameworks are great for RAD and applications that are only used in-house (because you can hack the backend to pieces without worries for security really, unless you must provide role based access in the application). We will be dealing with a simple page containing raw javascript and php.
There are at least two files required for a simple ajax example. One is an HTML file containing the javascript to make the request from the client to the web server. The other is a script to receive the request, process it, and return the information to the client javascript.
If you do not understand how a basic ajax request works, consider it nothing more than a client/server connection. The client is your visitor, and the server is of course your server. When you attach javascript to an HTML file, that javascript code is executed on the visitors machine and can save your server some memory as well as cpu cycles. The browser sees this javascript code and interprets it and then executes it. An ajax request is nothing more than using javascript to create a socket, send a request to your server, and process the returned data with javascript. A query would go as follows:
Clients requests www.mysite.com/index.html -> javascript code on index.html creates a socket on visitors computer -> socket sends request to www.mysite.com/ajax.php -> ajax.php processes the request and sends back information (aka "hello world") -> visitors computer gets the data ("hello world") and decides what to do with it on the page (show it as an alert, show it in a text box, show it as an error).
This allows an entire website to be built in such a way that the visitor actually never has to load another page. The entire website could simply be sent back and forth using ajax and show the returned data on the page as it gets it. Want an example of how this can be used in a very efficient manner? Take a glance at Bing Image Search. Do a search for anything and scroll down. Notice how you never have to click a "Next Page" to get more results, it simply continues to load new images as you scroll down, always staying one step ahead. Well, in this case it is nothing more than ajax being used and the request sent being "gather more images", and so bing.com passes back more images, and your web browser says, "add new images to image listing". Another example of this that most people don't notice is the search suggestion feature at Google. Notice if you type in a few words you will get suggestions of what to search for by Google. It simply passes what you type to google as you type it, and returns back searches related to what you have typed so far, your browser is told via javascript to "list them here". Pretty neat eh?
A simple ajax request (example code)
Let's dive into some code here and get our hands dirty. A quick "Hello World" example using ajax and php requires two files: ajax.php and ajax.html. The source code for these files is below. I would suggest you manually type them instead of simply copy and paste if you feel weak about understanding all of this. If you feel you have a good idea about what's going on go ahead and copy and paste. I only suggest manually typing it for newbies because it forces you to look at the code line by line and understanding it.
ajax.html
<html> <head><title>Ajax Hello World Example (www.amusingmarlow.com)</title></head> <script language="javascript"> function socketsetup() { if (window.XMLHttpRequest) httpsocket = new XMLHttpRequest(); else if (window.ActiveXObject) httpsocket = new ActiveXObject("Microsoft.XMLHTTP"); httpsocket.open("GET","ajax.php",true); httpsocket.onreadystatechange=socketreceive; if(window.XMLHttpRequest) httpsocket.send(null); else if(window.ActiveXObject) httpsocket.send(); } function socketreceive() { if(httpsocket.readyState==4) { if(httpsocket.status==200 || httpsocket.status==304) { document.getElementById('received').innerHTML=httpsocket.responseText; } } } </script> </head> <body> <div id="received"></div><br /> <input onclick="socketsetup();" type="button" value="Grab Data" /> </body> </html>
ajax.php
<?php echo 'Hello World. This is an ajax test.'; ?>
Save the two files above, upload them, and visit http://www.yoursite.com/ajax.html. You should see a blank page titled "Ajax Hello World Example" with a button saying "Grab Data". Click this button and you will instantly see the message from ajax.php (well, depending on how fast your server and computer are). Congratulations! You just ran your first ajax script.
The real question is, do you understand the code? No? Well that is fine, I will explain line by line exactly what is going on here.
- Sent (0)
- Nouveau
Générez vos vidéos d'entreprise par l'IA avec la voix ou simplement du texte
chatGPTaz.com
Parlez à ChatGPT dans votre langue maternelle
AppAIVidéo
Votre première application vidéo AI GRATUITE
Deepfake Video
Deepfake AI Video Maker
Deepfake
Deepfake AI Video Maker
AI Deep Fake
Deepfake AI Video Maker
AIvidio
AI Video Mobile Solutions
AIvideos
AI Video Platform & Solutions
AIvedio
AI Video App Maker
Artificial General Intelligence
Ai and higher level Artificial General Intelligence (AGI)
Artificial General Intelligence
Ai and higher level Artificial General Intelligence (AGI)
Faceswap AI en ligne
Échangez des visages, des vidéos, des photos et des GIF instantanément avec de puissants outils d'IA - Faceswap AI Online GRATUIT
Faceswap AI en ligne
Échangez des visages, des vidéos, des photos et des GIF instantanément avec de puissants outils d'IA - Faceswap AI Online GRATUIT
Faceswap AI en ligne
Échangez des visages, des vidéos, des photos et des GIF instantanément avec de puissants outils d'IA - Faceswap AI Online GRATUIT
Powerful AI Presentation PPT Maker for FREE
Build an impressive presentation with our free online AI presentation app
Your next top AI Assistant
Claude AI, developed by Anthropic
Your next top AI Assistant
Claude AI, developed by Anthropic
Temu gratuit 500 $ pour les nouveaux utilisateurs
Claim Free Temu $500 Credit via Affiliate & Influencer Program
Crédits publicitaires TikTok gratuits
Maîtrisez les publicités TikTok pour le marketing de votre entreprise
Dall-E-OpenAI.com
Générez automatiquement des images créatives avec l'IA
chatGPT4.win
Parlez à ChatGPT dans votre langue maternelle
Premier produit d'intelligence artificielle d'Elon Musk - Grok/UN.com
Parlez au chatbot Grok AI dans votre langue
Outily.win
Centre d'outils ouvert et gratuit, utilisable par tous et pour tous, avec des centaines d'outils
GateIO.gomymobi.com
Airdrops gratuits à réclamer et à partager jusqu'à 150 000 $ par projet
iPhoneKer.com
Économisez jusqu'à 630 $ à l'achat d'un nouvel iPhone 16
Acheter le robot Tesla Optimus
Commandez votre robot Tesla Bot : Optimus Gen 2 dès aujourd'hui pour moins de 20 000 $