Home Web Front-end JS Tutorial Example analysis of ajax implementation of three-level linkage writing

Example analysis of ajax implementation of three-level linkage writing

Oct 30, 2017 am 10:36 AM
ajax Writing method Linkage

Main page code

<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../wenjian/jquery-2.2.3.min.js"></script></head><body><select id="sheng">
    <option>请选择</option></select><select id="shi">
    <option >请选择</option></select><select id="qu">
    <option >请选择</option></select></body></html><script>
    $.ajax({
        data: {parent_id: 0}, //发送的数据        
        dataType: "json", //返回值的类型 text为string型        
        type: &#39;post&#39;,   //发送请求的方法(get)        
        url: &#39;sheng_l.php&#39;,//发送请求的地址        
        success: function (data) {//发送成功时的回调函数
    //            console.log(data);
            for (var i in data) {
                $("#sheng").append("<option value=&#39;"+ data[i][2] +"&#39;>" + data[i][1]  +"</option>")
            }
        }
    })
    $(document).ready(function () {
        $("#sheng").change(function () {
            $("#shi").get(0).options.length= 1;//            
            $("#qu").get(0).options.length= 1;
            var data = $("#sheng").find("option:selected").val();
            $.ajax({
                data:{parent_id:data},
                type:"post",
                dataType:"json",
                url:"sheng_l.php",
                success:function (data) {                    
                for(var i in data){
                        $("#shi").append("<option value=&#39;" + data[i][2] +"&#39;>" + data[i][1] +"</option>")
                    }
                }
            })
        })
    })
    $(document).ready(function () {
        $("#shi").change(function () {
            $("#qu").get(0).options.length= 1;            
            var data = $("#shi").find("option:selected").val();
            $.ajax({
                data:{parent_id:data},
                type:"post",
                dataType:"json",
                url:"sheng_l.php",
                success:function (data) {                    for (var i in data){
                        $("#qu").append("<option value=&#39;" +data[i][2] +"&#39;>" +data[i][1] +"</option>")
                    }
                }
            })
        })
    })
Copy after login

Processing page code

<?php/**
 * Created by fcc
 * User: Administrator
 * Date: 2017/10/29
 * Time: 20:56 */require_once "../wenjian/DBDA.class.php";$db = new DBDA();
 $sql = "select * from region WHERE father_id = {$_POST[&#39;parent_id&#39;]}";$result = $db->Query($sql);echo json_encode($result);
Copy after login

The above is the detailed content of Example analysis of ajax implementation of three-level linkage writing. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Zhengtu IPx classic animation 'Journey to the West' The journey to the west is fearless and fearless Zhengtu IPx classic animation 'Journey to the West' The journey to the west is fearless and fearless Jun 10, 2024 pm 06:15 PM

Journey through the vastness and set foot on the journey to the west! Today, Zhengtu IP officially announced that it will launch a cross-border cooperation with CCTV animation "Journey to the West" to jointly create a cultural feast that combines tradition and innovation! This cooperation not only marks the in-depth cooperation between the two major domestic classic brands, but also demonstrates the unremitting efforts and persistence of the Zhengtu series on the road of promoting Chinese traditional culture. Since its birth, the Zhengtu series has been loved by players for its profound cultural heritage and diversified gameplay. In terms of cultural inheritance, the Zhengtu series has always maintained respect and love for traditional Chinese culture, and skillfully integrated traditional cultural elements into the game, bringing more fun and inspiration to players. The CCTV animation "Journey to the West" is a classic that has accompanied the growth of generations.

How to solve the 403 error encountered by jQuery AJAX request How to solve the 403 error encountered by jQuery AJAX request Feb 20, 2024 am 10:07 AM

Title: Methods and code examples to resolve 403 errors in jQuery AJAX requests. The 403 error refers to a request that the server prohibits access to a resource. This error usually occurs because the request lacks permissions or is rejected by the server. When making jQueryAJAX requests, you sometimes encounter this situation. This article will introduce how to solve this problem and provide code examples. Solution: Check permissions: First ensure that the requested URL address is correct and verify that you have sufficient permissions to access the resource.

How to solve jQuery AJAX request 403 error How to solve jQuery AJAX request 403 error Feb 19, 2024 pm 05:55 PM

jQuery is a popular JavaScript library used to simplify client-side development. AJAX is a technology that sends asynchronous requests and interacts with the server without reloading the entire web page. However, when using jQuery to make AJAX requests, you sometimes encounter 403 errors. 403 errors are usually server-denied access errors, possibly due to security policy or permission issues. In this article, we will discuss how to resolve jQueryAJAX request encountering 403 error

How to get variables from PHP method using Ajax? How to get variables from PHP method using Ajax? Mar 09, 2024 pm 05:36 PM

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:

Basic syntax and application of callback functions in Java Basic syntax and application of callback functions in Java Jan 30, 2024 am 08:12 AM

Introduction to the basic writing and usage of Java callback functions: In Java programming, the callback function is a common programming pattern. Through the callback function, a method can be passed as a parameter to another method, thereby achieving indirect call of the method. The use of callback functions is very common in scenarios such as event-driven, asynchronous programming and interface implementation. This article will introduce the basic writing and usage of Java callback functions, and provide specific code examples. 1. Definition of callback function A callback function is a special function that can be used as a parameter

Double chef ecstasy! 'Onmyoji' x 'Hatsune Miku' collaboration starts on March 6 Double chef ecstasy! 'Onmyoji' x 'Hatsune Miku' collaboration starts on March 6 Feb 22, 2024 pm 06:52 PM

NetEase's "Onmyoji" mobile game announced today that the Onmyoji x Hatsune Miku limited collaboration will officially begin on March 6. The collaboration-limited SSR Hatsune Miku (CV: Saki Fujita) and SSR Kagamine Rin (CV: Asami Shimoda) are coming to Heian Kyo! The linkage online special performance event will officially start in the game on March 9~

Detailed explanation of how to write the less than sign in MyBatis Detailed explanation of how to write the less than sign in MyBatis Feb 21, 2024 pm 08:36 PM

Detailed explanation of how to write the less than sign in MyBatis MyBatis is an excellent persistence layer framework that is widely used in Java development. In the process of using MyBatis for database operations, we often use the less than sign (

How to solve the problem of jQuery AJAX error 403? How to solve the problem of jQuery AJAX error 403? Feb 23, 2024 pm 04:27 PM

How to solve the problem of jQueryAJAX error 403? When developing web applications, jQuery is often used to send asynchronous requests. However, sometimes you may encounter error code 403 when using jQueryAJAX, indicating that access is forbidden by the server. This is usually caused by server-side security settings, but there are ways to work around it. This article will introduce how to solve the problem of jQueryAJAX error 403 and provide specific code examples. 1. to make

See all articles