Spring mvc+jsp achieves level three linkage

Source: Internet
Author: User

JSP code

<script type="Text/javascript">$ (function () {initprovinces ();    }); /** * Get list of provinces*/function Initprovinces () {$ ('#province'). empty (); $.ajax ({type:"POST", Url:basepath+"district/getprovinces.do", Success:function (data) {$.each (data, function (I, it) {$ ("<option value= '"+ It.id +"'/>"+ It.name +"<br>"). Click (function () {initcities (it.id); }). AppendTo ($ ('#province'));            });    }       }); }    /** * Get city list*/function Initcities (Provinceid) {$ ('#city'). empty (); $.ajax ({type:"POST", Url:basepath+"district/getcities.do?province="+Provinceid, success:function (data) {$.each (data, function (I, it) {$ ( "<option value= '"+ It.id +"'/>"+ It.name +"<br>"). Click (function () {initcounties (it.id); }). AppendTo ($ ('#province'));            });    }        }); }    /** * Get a list of counties*/function Initcounties (Cityid) {$ ('#county'). empty (); $.ajax ({type:"POST", Url:basepath+"district/getcounties.do?city="+Cityid, success:function (data) {$.each (data, function (I, it) {$ ("<option value= '"+ It.id +"'/>"+ It.name +"<br>"). AppendTo ($ ('#province'));            }); } });}//...</script><body>Select region:<SelectId='Province'><option>---province---</option></Select> <SelectId=' City'><option>---City---</option></Select> <SelectId='County'><option>---area---</option></Select></body>Spring MVC Code: @Controller @requestmapping (Value="/district") Public classDistrictcontroller {@ResourcePrivateDistrictservice Districtservice;/** * Get province list * @return * @throws Exception*/@RequestMapping (Value="getprovinces") @ResponseBody PublicObject getprovinces () throws Exception {returndistrictservice.getprovinces ();} /** * Get city list * @param province * @return * @throws Exception*/@RequestMapping (Value="getcities") @ResponseBody PublicObject getcities (@RequestParam (value ="Province") String province) throws Exception {returndistrictservice.getcities ();} //the next level of access and GetCities methods are the same, so this is skipped}

Spring mvc+jsp achieves level three linkage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.