zoukankan      html  css  js  c++  java
  • JavaScript之使用AJAX(适合初学者)

      网上关于AJAX的教程和分享层出不穷,现实生活中关于AJAX的书籍也是琳琅满目,然而太多的选择容易令人眼花缭乱,不好取舍。事实是,一般的教程或书籍都不会讲Web服务器的搭建,因此,对于初学者(比如笔者)来说,好不容易学习了AJAX的知识,却还是没有办法亲身实践操作一把,这是多大的遗憾啊!
      所以这一次,笔者将会举一个简单的AJAX应用实例,来详细地讲述如何在本地电脑上使用AJAX来满足Web开发要求。
      首先,我们需要在自己的电脑上安装好XAMPP,这是为了开启Apache服务器,这样就不需要我们自己再去搭建服务器。XAMPP的下载地址为:https://www.apachefriends.org/zh_cn/index.html .
      下载完后直接安装即可。笔者下载的Window版本,安装完后,打开XAMPP Control Panel,点击“Apache”前面的按钮来安装Apache服务,并点击“Apache”后面的start按钮以开启Apache服务,如下图所示:

    ![开启Apache服务](http://img.blog.csdn.net/20180117161025730?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamNsaWFuOTE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
    Apache的默认端口应为443,笔者因为该端口已被占用,故改为4431.   接着我们在XAMPP的安装目录下的htdocs的文件夹下分别新建一个HTML文件:programming_language_intro.html和PHP文件:intro.php,如下如所示:
    ![新建文件](http://img.blog.csdn.net/20180117161614027?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamNsaWFuOTE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
      其中programming_language_intro.html的代码如下: ```html

    Programming Language Introduction

    Language:

    Introduction:

    ``` 在showIntro()中使用了AJAX,关于AJAX的具体教程可以参考:http://www.runoob.com/ajax/ajax-tutorial.html .   intro.php的代码如下:(PHP语言) ```PHP $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 languages in 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 developing statistical 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 ,得到的页面如下:
    <center>
    ![programming_language_intro.html](http://img.blog.csdn.net/20180117163841535?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamNsaWFuOTE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
    </center>
    &emsp;&emsp;在下拉菜单中选择"JavaScript",则页面如下:
    <center>
    ![JavaScript介绍](http://img.blog.csdn.net/20180117163235236?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamNsaWFuOTE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
    </center>
    &emsp;&emsp;在下拉菜单中选择"Python",则页面如下:
    <center>
    ![JavaScript介绍](http://img.blog.csdn.net/20180117163336722?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamNsaWFuOTE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
    </center>
    &emsp;&emsp;笔者的学习心得:有时候光看网上或书上的教程,是远远不够的,因为可能并没有讲如何具体地操作实践,最好的学习方法还是自己亲自实践一把,然后写个Blog记录之~~
    &emsp;&emsp;本次分享到此结束,欢迎大家交流~~
  • 相关阅读:
    TODO supply a title
    three.js ---- 3d页面开发入门
    ProgressBar.Style ---- Marquee
    C#中的Task.Delay()延迟与异步执行返回结果
    位运算-实现加减乘除
    2020年专项附加扣除信息,个税纳税记录查询
    C#动态执行JS和VBS脚本
    windows下bat批处理实现守护进程(有日志)
    C#创建快捷方式的两种方法
    C#中创建程序的快捷方式
  • 原文地址:https://www.cnblogs.com/jclian91/p/8303732.html
Copyright © 2011-2022 走看看