日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

JavaScript之使用AJAX(适合初学者)

發(fā)布時間:2025/3/18 javascript 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JavaScript之使用AJAX(适合初学者) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

??網(wǎng)上關(guān)于AJAX的教程和分享層出不窮,現(xiàn)實生活中關(guān)于AJAX的書籍也是琳瑯滿目,然而太多的選擇容易令人眼花繚亂,不好取舍。事實是,一般的教程或書籍都不會講Web服務(wù)器的搭建,因此,對于初學(xué)者(比如筆者)來說,好不容易學(xué)習(xí)了AJAX的知識,卻還是沒有辦法親身實踐操作一把,這是多大的遺憾啊!
??所以這一次,筆者將會舉一個簡單的AJAX應(yīng)用實例,來詳細(xì)地講述如何在本地電腦上使用AJAX來滿足Web開發(fā)要求。
??首先,我們需要在自己的電腦上安裝好XAMPP,這是為了開啟Apache服務(wù)器,這樣就不需要我們自己再去搭建服務(wù)器。XAMPP的下載地址為:https://www.apachefriends.org/zh_cn/index.html .
??下載完后直接安裝即可。筆者下載的Window版本,安裝完后,打開XAMPP Control Panel,點擊“Apache”前面的按鈕來安裝Apache服務(wù),并點擊“Apache”后面的start按鈕以開啟Apache服務(wù),如下圖所示:




Apache的默認(rèn)端口應(yīng)為443,筆者因為該端口已被占用,故改為4431.
??接著我們在XAMPP的安裝目錄下的htdocs的文件夾下分別新建一個HTML文件:programming_language_intro.html和PHP文件:intro.php,如下如所示:



??其中programming_language_intro.html的代碼如下:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script> function showIntro(){//所有現(xiàn)代瀏覽器均支持XMLHttpRequest對象(IE5和IE6使用ActiveXObject)//XMLHttpRequest用于在后臺與服務(wù)器交換數(shù)據(jù)var xmlhttp = new XMLHttpRequest();var str = document.getElementById("language").value;//onreadystatechange:存儲函數(shù)(或函數(shù)名),每當(dāng)readyState屬性改變時,就會調(diào)用該函數(shù)//readyState:4表示請求已完成,且響應(yīng)已就緒//status:200表示"OK"xmlhttp.onreadystatechange = function(){if (xmlhttp.readyState==4 && xmlhttp.status==200){document.getElementById("p1").innerHTML = "Introduction of "+str+":";//獲取來自服務(wù)器的響應(yīng):responseText表示獲得字符串形式的響應(yīng)數(shù)據(jù)document.getElementById("intro").innerHTML = xmlhttp.responseText;}}//將請求發(fā)送到服務(wù)器//open()的三個參數(shù)分別為:GET請求或POST請求,url:服務(wù)器上的文件,異步:是或否xmlhttp.open("GET","intro.php?query="+str,true);xmlhttp.send(); }//刷新頁面 function refresh_page(){location.reload(); } </script> </head> <body><h3>Programming Language Introduction</h3> <form action=""> Language: <select id='language'><option>C</option><option>HTML</option><option>Java</option><option>JavaScript</option><option>PHP</option><option>Python</option><option>R</option><option>Scala</option></select> </form> <br> <button onclick="showIntro()">SHOW</button> <button onclick="refresh_page()">REFRESH</button> <p id='p1'>Introduction: </p> <p><span id="intro"></span></p></body> </html>

在showIntro()中使用了AJAX,關(guān)于AJAX的具體教程可以參考:http://www.runoob.com/ajax/ajax-tutorial.html .
??intro.php的代碼如下:(PHP語言)

<?php //$intro:Associative Array, keys are programming languages $intro = array();$intro["C"] = "C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language, including operating systems, as well as various application software for computers ranging from supercomputers to embedded systems.";$intro["HTML"] = "Hypertext Markup Language (HTML) is the standard markup language for creating web pages and web applications. With Cascading Style Sheets (CSS) and JavaScript it forms a triad of cornerstone technologies for the World Wide Web. Web browsers receive HTML documents from a web server or from local storage and render them into multimedia web pages. HTML describes the structure of a web page semantically and originally included cues for the appearance of the document.";$intro["Java"] = "Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented,[15] and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers 'write once, run anywhere' (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM)regardless of computer architecture. As of 2016, Java is one of the most popular programming languagesin use, particularly for client-server web applications, with a reported 9 million developers. Java was originally developed by James Gosling at Sun Microsystems (which has since been acquired by Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++, but it has fewer low-level facilities than either of them.";$intro["JavaScript"] = "JavaScript often abbreviated as JS, is a high-level, dynamic, weakly typed, prototype-based, multi-paradigm, and interpreted programming language. Alongside HTML and CSS, JavaScript is one of the three core technologies of World Wide Web content production. It is used to make webpages interactive and provide online programs, including video games. The majority of websitesemploy it, and all modern web browsers support it without the need for plug-ins by means of a built-in JavaScript engine. Each of the many JavaScript engines represent a different implementationof JavaScript, all based on the ECMAScript specification, with some engines not supporting the spec fully, and with many engines supporting additional features beyond ECMA.";$intro["PHP"] = "PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. Originally created by Rasmus Lerdorf in 1994, the PHP reference implementation is now produced by The PHP Group. PHP originally stood for Personal Home Page, but it now stands for the recursive backronym PHP: Hypertext Preprocessor";$intro["Python"] = "Python is an interpreted high-level programming language for general-purpose programming. Created by Guido van Rossumand first released in 1991, Python has a design philosophy that emphasizes code readability, and a syntax that allows programmers to express concepts in fewer lines of code, notably using significant whitespace. It provides constructs that enable clear programming on both small and large scales.";$intro["R"] = "R is a free (libre) programming language and software environment for statistical computing and graphics that is supportedby the R Foundation for Statistical Computing. The R language is widely used among statisticians and data miners for developingstatistical software and data analysis. Polls, surveys of data miners, and studies of scholarly literature databases show that R's popularity has increased substantially in recent years. R ranks 8th in the TIOBE index.";$intro["Scala"] = "Scala is a general-purpose programming language providing support for functional programming and a strong static type system.Designed to be concise, many of Scala's design decisions aimed to address criticisms of Java.";//get the query parameter from URL $query = $_GET["query"]; echo $intro[$query]; ?>

??在瀏覽器中輸入http://localhost/programming_language_intro.html ,得到的頁面如下:




??在下拉菜單中選擇”JavaScript”,則頁面如下:



??在下拉菜單中選擇”Python”,則頁面如下:



??筆者的學(xué)習(xí)心得:有時候光看網(wǎng)上或書上的教程,是遠(yuǎn)遠(yuǎn)不夠的,因為可能并沒有講如何具體地操作實踐,最好的學(xué)習(xí)方法還是自己親自實踐一把,然后寫個Blog記錄之~~
??本次分享到此結(jié)束,歡迎大家交流~~

總結(jié)

以上是生活随笔為你收集整理的JavaScript之使用AJAX(适合初学者)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 欧美肉丝袜videos办公室 | 午夜精品久久久久久久99老熟妇 | wwww黄色片| 久久永久视频 | 日韩av二区 | 国产精品9| 欧美日韩人妻精品一区二区三区 | 国产一级片免费在线观看 | 日韩欧美国产成人精品免费 | 欧美午夜激情影院 | www.久久网 | 久草青青视频 | 可以免费看的毛片 | av丝袜在线 | 国产欧美日韩激情 | 国产夜夜操| 国产男男gay | 青青草婷婷 | 最新版天堂资源在线 | 黄色美女视频网站 | www.狠狠艹 | 国产欧美另类 | aaa级黄色片 | 无码国内精品人妻少妇蜜桃视频 | 欧美深夜在线 | 精品99999 | 久久午夜福利电影 | 男ji大巴进入女人视频 | 很黄很色的视频 | 午夜精品视频在线观看 | 欧美成人r级一区二区三区 中文无码一区二区三区在线观看 | 亚洲婷婷在线观看 | 欧美浓毛大泬视频 | 欧美爽爽 | 国产男女猛烈无遮挡免费视频动漫 | 少妇三级 | 欧美性天天影院 | 亚洲精品aa | 亚洲国产精品美女 | 免费萌白酱国产一区二区三区 | 18岁免费观看电视连续剧 | 黑人毛片网站 | 91大奶 | 97国产成人无码精品久久久 | 日本午夜一级 | 丁香六月综合 | 一区二区传媒有限公司 | 成人性生交大片免费看r链接 | 7777精品久久久久久 | 最近更新中文字幕 | 91精东传媒理伦片在线观看 | 538国产精品一区二区免费视频 | 老头老太吃奶xb视频 | 久久99精品国产.久久久久久 | 亚洲一级av毛片 | 99精品国产一区 | 午夜伦视频 | 亚洲精品三级 | 亚洲色图一区二区 | 伊人99re | 青青操在线观看视频 | 少妇无码一区二区三区 | 亚洲成熟毛多妇女av毛片 | 色屁屁www影院免费观看入口 | 亚洲精品888 | 男女免费视频网站 | 日韩av在线一区二区三区 | 日本wwww色| 国内三级视频 | 一区二区免费在线播放 | 日韩黄色片在线观看 | 久久久久久久久久99精品 | 伊人久久大香网 | 精品视频中文字幕 | 91视频影院| 国产视频一区二区视频 | 一级网站在线观看 | 奇米影视狠狠 | 99蜜桃臀久久久欧美精品网站 | 久草网视频在线观看 | 亚洲av永久纯肉无码精品动漫 | 亚洲综合一区二区三区 | 日韩欧美在线视频观看 | 成人短视频在线播放 | 我色综合 | 男人吃奶视频 | 久操热线| 欧美日韩中文字幕在线观看 | 国产精品国产三级国产专播精品人 | 青青久久av | 黑人大群体交免费视频 | 日韩精品一区二区三区av | 国产三区av| 久久久青草 | 69堂在线观看 | 欧美日韩国产图片 | 国产成人亚洲综合a∨婷婷 台湾a级片 | 免费成人深夜夜行网站视频 | 2021亚洲天堂 |