php关于省市区更新界面加载的问题-多级联动加载问题(思路)
思路探讨–共同研究
PHP后台和前端联合写省市区多级联动,我想写过网站的或者开发软件的都遇到过(这篇博客以网站开发逻辑为例),常用的方法是
通过后台将省的地址给前端,然后前端加载,写个触发器依次ajax请求相应的市\区的数据。
这种逻辑在正常选择加载的时候十分的适用,但是问题出在当需要界面加载初给定一个完整的省市区地址时,初次加载页面既要考虑到服务器 资源利用以及用户体验时就产生了矛盾。
上述我们说的方法,在平时选择时每一个步骤都是对数据库资源的合理利用,但是在初次加载时,写触发器展现初始的省市区地址就要先后请求 三次服务器,这样就显得很没必要且服务器情况不理想的情况下界面加载会十分的慢,显然是不合适的。但是我们要注意的是,在服务器状况很好的 时候,这种操作完全可以展现预期效果。
上述方法对服务器资源十分的浪费,这点毋庸置疑,所以为了应对开发需求,在原来的基础上就界面加载进行了处理。初次加载时给省市区的名字然后前端赋值在 下拉选择框中,这方法资源问题肯定是不会浪费的,但是界面会很死,在不重新选择省的情况下市和区的下拉选择项是为空的,用户体验差。
我也在这两种方式的选择中纠结过,当前辈和我说这两种方式的区别时,我陷入了沉默。通过一段时间的思考,我发现了一个取中的方法,我们依然使用原来的联动架构 ,区别在于首次加载时我们放弃以上的两种方式,让后台根据初次加载需要显示的的省市区名字到数据库对应的生成三个数组(数据内容与ajax中的数据要一致),然后将 数组和选定省市区的id传给前端,前端可以根据你给的数据,自己遍历数组,找到固定值。(其实说了这么多,实际上就是让后台自己模拟一次选择操作,将原本需要请求的数据一次打包给前端)。
其实问题很简单,但却很细节,我的想法不一定就是最好的,我也没有这样想过,有不同的意见,或者更好的方法可以留言。谢谢!
本文永久地址:http://blog.it985.com/15601.html
本文出自IT985博客 ,转载时请注明出处及相应链接。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Alipay PHP...

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
