AJAX和WebService實(shí)現(xiàn)省市縣三級聯(lián)動(dòng)具體代碼_AJAX教程
推薦:ajax 登錄功能簡單實(shí)現(xiàn)(未連接數(shù)據(jù)庫)未連接數(shù)據(jù)庫下實(shí)現(xiàn)ajax 登錄功能判斷登陸成功與失敗,喜歡ajax的朋友可以參考下哈,希望對大家有所幫助
-------------------------------------WebService1.asmx---------------------------------------復(fù)制代碼 代碼如下:www.hl5o.cn
// 若要允許使用 ASP.NET AJAX 從腳本中調(diào)用此 Web 服務(wù),請取消對下行的注釋。
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public List<Model.province> GetProvince()
{
BLL.province bpro = new BLL.province();
List<Model.province> list = bpro.GetListModel();
return list;
}
[WebMethod]
public List<Model.city> GetCityByPro(string proid)
{
BLL.city bcity = new BLL.city();
List<Model.city> list = bcity.GetListModel("father='" + proid + "'");
return list;
}
[WebMethod]
public List<Model.area> GetAreaByCity(string cityid)
{
BLL.area barea = new BLL.area();
List<Model.area> list = barea.GetListModel("father='" + cityid + "'");
return list;
}
----------------------------------HTMLPage1.htm----------------------------
復(fù)制代碼 代碼如下:www.hl5o.cn
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
select
{
width: 150px;
}
</style>
<script src="js/Jquery1.7.js" type="text/javascript"></script>
<script type="text/javascript">
$(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; i++) {
stroption += '<option value=' + result.d[i].provinceID + '>';
stroption += result.d[i].provincename;
stroption += '</option>';
}
$('#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; i++) {
strocity += '<option value=' + result.d[i].cityID + '>';
strocity += result.d[i].cityname;
strocity += '</option>';
}
$('#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; i++) {
stroarea += '<option value=' + result.d[i].areaID + '>';
stroarea += result.d[i].areaname;
stroarea += '</option>';
}
$('#searea').append(stroarea);
}
})
})
})
</script>
</head>
<body>
<table>
<tr>
<td>
地址
</td>
<td>
<select id="seprovince">
<option>--請選擇--</option>
</select>
省
<select id="secity">
<option>--請選擇--</option>
</select>市
<select id="searea">
<option>--請選擇--</option>
</select>縣
</td>
</tr>
</table>
</body>
</html>

注:用到了三層架構(gòu),dal層寫了一些方法
分享:AJAX和WebService實(shí)現(xiàn)郵箱驗(yàn)證(無刷新驗(yàn)證郵件地址是否合法)首先在項(xiàng)目里面添加服務(wù)引用,驗(yàn)證 Email 地址是否正確(郵件地址合法、只是域名正確、郵件服務(wù)器沒有找到等等)感興趣的朋友可以參考下哈
相關(guān)AJAX教程:
- Ajax中瀏覽器的緩存問題解決方法
- ajax 登錄功能簡單實(shí)現(xiàn)(未連接數(shù)據(jù)庫)
- AJAX和WebService實(shí)現(xiàn)郵箱驗(yàn)證(無刷新驗(yàn)證郵件地址是否合法)
- AJAX和三層架構(gòu)實(shí)現(xiàn)分頁功能具體思路及代碼
- 使用AJAX返回WebService里的集合具體實(shí)現(xiàn)
- AJAX獲取服務(wù)器當(dāng)前時(shí)間及時(shí)間格式輸出處理
- ajax傳遞多個(gè)參數(shù)具體實(shí)現(xiàn)
- ajax傳遞一個(gè)參數(shù)具體實(shí)現(xiàn)
- 滑輪滾動(dòng)到頁面底部ajax加載數(shù)據(jù)配合jsonp實(shí)現(xiàn)探討
- jQery ajax——load()方法示例介紹
- jQuery+Ajax實(shí)現(xiàn)表格數(shù)據(jù)不同列標(biāo)題排序(為表格注入活力)
- 利用Ajax實(shí)現(xiàn)在腳本里傳值實(shí)例介紹
AJAX教程Rss訂閱編程教程搜索
AJAX教程推薦
猜你也喜歡看這些
- AJAX和傳統(tǒng)的ASP無刷新技術(shù)比較
- 如何解決Ajax中文亂碼問題
- 如何根據(jù)郵編自動(dòng)完成地址信息
- 解讀jsp+ajax自動(dòng)刷新實(shí)例
- 巧用Ajax和RSS做個(gè)人門戶網(wǎng)站
- Ajax技術(shù)實(shí)踐之完成Ajax自動(dòng)完成功能
- 揭秘AJAX將成為移動(dòng)Web2.0時(shí)代首選開發(fā)平臺(tái)
- 多ajax請求的各類解決方案(同步, 隊(duì)列, cancel請求)
- 解析AJAX中的一些關(guān)鍵技術(shù)
- Ajax標(biāo)簽導(dǎo)航實(shí)例詳解-Javascript技巧篇
- 相關(guān)鏈接:
復(fù)制本頁鏈接| 搜索AJAX和WebService實(shí)現(xiàn)省市縣三級聯(lián)動(dòng)具體代碼
- 教程說明:
AJAX教程-AJAX和WebService實(shí)現(xiàn)省市縣三級聯(lián)動(dòng)具體代碼
。