Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the three-level linkage between AJAX and WebService in provinces, cities and counties

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how AJAX and WebService achieve the three-level linkage of provinces, cities and counties, I believe most people do not know much about it, so share this article for your reference. I hope you will gain a lot after reading this article. Let's learn about it together.

-- WebService1.asmx--

The code is as follows:

/ / to allow this Web service to be called from a script using ASP.NET AJAX, uncomment the following line.

[System.Web.Script.Services.ScriptService]

Public class WebService1: System.Web.Services.WebService

{

[WebMethod]

Public string HelloWorld ()

{

Return "Hello World"

}

[WebMethod]

Public List GetProvince ()

{

BLL.province bpro = new BLL.province ()

List list = bpro.GetListModel ()

Return list

}

[WebMethod]

Public List GetCityByPro (string proid)

{

BLL.city bcity = new BLL.city ()

List list = bcity.GetListModel ("father='" + proid + "'")

Return list

}

[WebMethod]

Public List GetAreaByCity (string cityid)

{

BLL.area barea = new BLL.area ()

List list = barea.GetListModel ("father='" + cityid + "'")

Return list

}

-- HTMLPage1.htm--

The copy code is as follows:

Select

{

Width: 150px

}

$(function () {)

$.ajax ({

Type: "post"

ContentType: "application/json"

Url: "WebService1.asmx/GetProvince"

Data: "{}"

Success: function (result) {

Var stroption =''

For (var I = 0; I < result.d.length; iTunes +) {

Stroption + =''

Stroption + = result.d [I] .provincename

Stroption + =''

}

$('# seprovince') .append (stroption)

}

})

$('# seprovince') .change (function () {

$('# secity option:gt (0)'). Remove ()

$('# searea option:gt (0)'). Remove ()

$.ajax ({

Type: "post"

ContentType: "application/json"

Url: "WebService1.asmx/GetCityByPro"

Data: "{proid:'" + $(this). Val () + "'}"

Success: function (result) {

Var strocity =''

For (var I = 0; I < result.d.length; iTunes +) {

Strocity + =''

Strocity + = result.d [I] .cityname

Strocity + =''

}

$('# secity') .append (strocity)

}

})

})

$('# secity') .change (function () {

$('# searea option:gt (0)'). Remove ()

$.ajax ({

Type: "post"

ContentType: "application/json"

Url: "WebService1.asmx/GetAreaByCity"

Data: "{cityid:'" + $(this). Val () + "'}"

Success: function (result) {

Var stroarea =''

For (var I = 0; I < result.d.length; iTunes +) {

Stroarea + =''

Stroarea + = result.d [I] .areaname

Stroarea + =''

}

$('# searea') .append (stroarea)

}

})

})

})

Address

Please select--

Province

Please select--

Market

Please select--

County

Note: using a three-tier architecture, the dal layer writes some methods

The above is all the contents of the article "how to achieve the three-level linkage between AJAX and WebService at the provincial, municipal and county levels". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report