Ajax implements unlimited list loading and two-level drop-down options, ajax drop-down
Ajax performs list loading without limit and Ajax performs two-level drop-down options for your reference. The specific content is as follows:
// Add the public function ajaxlist () {// echo "http: // www. Domain Name. com/index. php? A = Index & c = Index & m = ajaxlist "; // echo"
Page implementation:
<Script type = 'text/javascript '>/* ajax */(function () {// send data var url = "_ WEB _" + "? A = Index & c = Index & m = ajaxlist "; var oSum =''; $ ('a. ajaxBut '). click (function () {oSum = $ ('div. zizhiListContBox> '). size (); $. post (url, {sum: oSum}, function (result) {console. log (result); eval ("var info =" + result); for (var key in info) {oStr = "<a href = '" + "_ WEB _" + "? A = Index & c = Index & m = content & mid = 1 & cid = 33 & aid = "+ info [key] ['aid '] +" "+"'>
Second-level options for Ajax:
<! -- Example: HTML --> <dl class = "pr keshi"> <dt class = "pa"> department: </dt> <dd class = "pa"> <select name = 'keshi' class ='m _ keshi'> <option value = '0'> -- select a department -- </option> </select> <select name = 'zhuanjia 'class ='m _ zhuanjia'> <option> -- select an expert. </option> </select> </dd> </dl>
Example controller:
// Example Controller/* Ajax request topic list */public function ajaxlanmu () {$ lanmuList = M ('category ')-> where ('pid = 100 ') -> select (); $ this-> ajax ($ lanmuList);} public function ajaxzhuanjia () {$ where = array (); $ data = Q ('sum '); $ data = $ data? $ Data: 143; $ where ['cid'] = $ data; $ zhuanjiaList = M ('guahao')-> where ($ where)-> select (); $ this-> ajax ($ zhuanjiaList );}
Example: JS
<Script> (function () {var lanmuUrl = "_ WEB _" + "? A = Index & c = Index & m = ajaxlanmu "; var zhuanjiaUrl =" _ WEB _ "+ "? A = Index & c = Index & m = ajaxzhuanjia "; var oSum = oStr = oStr2 = oVal = oKong = info2 = oCid ='';/* lanmu */$. post (lanmuUrl, function (result) {eval ("var info =" + result); for (var key in info) {oStr + = "<option value = '" + info [key] ['catname'] + "'cid ='" + info [key] ['cid'] +" '> "+ info [key] ['catname'] +" </option> ";}; $ ('dl. keshi '). find ('select. m_keshi '). append (oStr) ;});/* zhuanjia */$ ('dl. keshi '). find ('select. m_keshi '). change (function () {oVal = $ (this ). find ('option: selected '). val (); if (oVal = 0) {evaluate ("<option> -- select an expert -- </option>") ;}else {oCid = $ (this ). find ('option: selected '). attr ('cid'); $. post (zhuanjiaUrl, {sum: oCid}, function (result) {eval ("info2 =" + result); oStr2 = ''; // note that you need to clear the data in the first request for (var key2 in info2) {oStr2 + = "<option value = '" + info2 [key2] ['title'] + "'>" + info2 [key2] ['title'] + "</ option> ";}; certificate ('dl.zhuanjia'hangzhou.find('select.m_zhuanjia'hangzhou.html (oStr2) ;}};}) ;}) (); </script>
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.