Home Web Front-end JS Tutorial Ajax realizes infinite loading of lists and secondary drop-down option effects

Ajax realizes infinite loading of lists and secondary drop-down option effects

May 22, 2018 am 10:57 AM
ajax load unlimited

This article mainly introduces Ajax to achieve infinite loading of lists and the effect of secondary drop-down options in detail. It has certain reference value. Interested friends can refer to

Ajax to achieve unlimited loading of lists. Make secondary drop-down options with Ajax for your reference. The specific content is as follows

//栏目Ajax做加载
public function ajaxlist(){
 //echo "http://www.域名.com/index.php?a=Index&c=Index&m=ajaxlist";
 //echo "<hr>";
 $data = Q(&#39;sum&#39;);
 $where = array();
 $where[&#39;cid&#39;] = 33;
 $rongyuList = M(&#39;content&#39;)->limit($data,2)->where($where)->select();
 $data[&#39;stat&#39;] = 1;
 $data = $rongyuList;
 $this->ajax($data);
 //也可以手动把想要的字段拼接成字符串 
 /*echo "[";
 foreach($rongyuList as $k){
  echo "{"."\""."title"."\"".":"."\"".$k[&#39;title&#39;]."\"".","."\""."description"."\"".":"."\"".$k[&#39;description&#39;]."\"".","."\""."cid"."\"".":"."\"".$k[&#39;cid&#39;]."\""."}".",";  
 }
 echo "]";*/
 }
Copy after login

Specific page implementation:

<script type=&#39;text/javascript&#39;>
/*ajax*/
(function(){
//发送数据 
var url = "__WEB__"+"?a=Index&c=Index&m=ajaxlist";
var oSum = &#39;&#39;; 
$(&#39;a.ajaxBut&#39;).click(function(){
 oSum = $(&#39;p.zizhiListContBox>a&#39;).size();
 $.post(url,{sum:oSum},function(result){
 console.log(result);
 eval("var info="+result);
 for(var key in info){
   oStr = "<a href=&#39;"+"__WEB__"+"?a=Index&c=Index&m=content&mid=1&cid=33&aid="+info[key][&#39;aid&#39;]+""+"&#39;><h3 class=&#39;f100 f16 ts500&#39;>"+info[key][&#39;title&#39;]+"</h3><p>"+info[key][&#39;description&#39;]+"</p><span class=&#39;b parb&#39;></span></a>";
   $(&#39;p.zizhiListContBox&#39;).append(oStr);
 };
 });
});
})();
</script>
Copy after login

Ajax makes secondary options:

<!-- 示例:HTML -->
<dl class="pr keshi" >
 <dt class="pa">科室:</dt>
 <dd class="pa">
  <select name=&#39;keshi&#39; class=&#39;m_keshi&#39;>
   <option value=&#39;0&#39;>--请选择科室--</option>
  </select>
  <select name=&#39;zhuanjia&#39; class=&#39;m_zhuanjia&#39;>
   <option>--请选择专家--</option>
  </select>
 </dd>
</dl>
Copy after login

Example controller:

//示例控制器
/* Ajax请求栏目列表 */
public function ajaxlanmu(){
 $lanmuList = M(&#39;category&#39;)->where(&#39;pid=142&#39;)->select();
 $this->ajax($lanmuList);
}
public function ajaxzhuanjia(){
 $where = array();
 $data = Q(&#39;sum&#39;);
 $data = $data ? $data : 143;
 $where[&#39;cid&#39;] = $data;
 $zhuanjiaList = M(&#39;guahao&#39;)->where($where)->select();
 $this->ajax($zhuanjiaList);
}
Copy after login

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 = &#39;&#39;;
/* lanmu */
$.post(lanmuUrl,function(result){
 eval("var info="+result);
 for(var key in info){oStr += "<option value=&#39;"+info[key][&#39;catname&#39;]+"&#39; cid=&#39;"+info[key][&#39;cid&#39;]+"&#39;>"+info[key][&#39;catname&#39;]+"</option>";};
 $(&#39;dl.keshi&#39;).find(&#39;select.m_keshi&#39;).append(oStr);
});
/* zhuanjia */
$(&#39;dl.keshi&#39;).find(&#39;select.m_keshi&#39;).change(function(){
 oVal = $(this).find(&#39;option:selected&#39;).val();
 if(oVal == 0){
  $(&#39;dl.zhuanjia&#39;).find(&#39;select.m_zhuanjia&#39;).html("<option>--请选择专家--</option>");
 }else{
  oCid = $(this).find(&#39;option:selected&#39;).attr(&#39;cid&#39;);
  $.post(zhuanjiaUrl,{sum:oCid},function(result){
   eval("info2="+result);
   oStr2 = &#39;&#39;;//注意这里要清空第一次请求的数据
   for(var key2 in info2){
    oStr2 += "<option value=&#39;"+info2[key2][&#39;title&#39;]+"&#39;>"+info2[key2][&#39;title&#39;]+"</option>";    
   };
   $(&#39;dl.zhuanjia&#39;).find(&#39;select.m_zhuanjia&#39;).html(oStr2);
  });
 };
});
})();
</script>
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

ajaxwith cross-domain jsonp

django via ajax Methods for completing email user registration and activating accounts

Detailed explanation of the use of get and post methods of nativeajax

The above is the detailed content of Ajax realizes infinite loading of lists and secondary drop-down option effects. 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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Error loading plugin in Illustrator [Fixed] Error loading plugin in Illustrator [Fixed] Feb 19, 2024 pm 12:00 PM

When launching Adobe Illustrator, does a message about an error loading the plug-in pop up? Some Illustrator users have encountered this error when opening the application. The message is followed by a list of problematic plugins. This error message indicates that there is a problem with the installed plug-in, but it may also be caused by other reasons such as a damaged Visual C++ DLL file or a damaged preference file. If you encounter this error, we will guide you in this article to fix the problem, so continue reading below. Error loading plug-in in Illustrator If you receive an "Error loading plug-in" error message when trying to launch Adobe Illustrator, you can use the following: As an administrator

Stremio subtitles not working; error loading subtitles Stremio subtitles not working; error loading subtitles Feb 24, 2024 am 09:50 AM

Subtitles not working on Stremio on your Windows PC? Some Stremio users reported that subtitles were not displayed in the videos. Many users reported encountering an error message that said "Error loading subtitles." Here is the full error message that appears with this error: An error occurred while loading subtitles Failed to load subtitles: This could be a problem with the plugin you are using or your network. As the error message says, it could be your internet connection that is causing the error. So please check your network connection and make sure your internet is working properly. Apart from this, there could be other reasons behind this error, including conflicting subtitles add-on, unsupported subtitles for specific video content, and outdated Stremio app. like

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

PHP and Ajax: Building an autocomplete suggestion engine PHP and Ajax: Building an autocomplete suggestion engine Jun 02, 2024 pm 08:39 PM

Build an autocomplete suggestion engine using PHP and Ajax: Server-side script: handles Ajax requests and returns suggestions (autocomplete.php). Client script: Send Ajax request and display suggestions (autocomplete.js). Practical case: Include script in HTML page and specify search-input element identifier.

Outlook freezes when inserting hyperlink Outlook freezes when inserting hyperlink Feb 19, 2024 pm 03:00 PM

If you encounter freezing issues when inserting hyperlinks into Outlook, it may be due to unstable network connections, old Outlook versions, interference from antivirus software, or add-in conflicts. These factors may cause Outlook to fail to handle hyperlink operations properly. Fix Outlook freezes when inserting hyperlinks Use the following fixes to fix Outlook freezes when inserting hyperlinks: Check installed add-ins Update Outlook Temporarily disable your antivirus software and then try creating a new user profile Fix Office apps Program Uninstall and reinstall Office Let’s get started. 1] Check the installed add-ins. It may be that an add-in installed in Outlook is causing the problem.

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

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:

See all articles