列表排序同一个name的表单怎么用serizelize()序列化
请教下问题,列表排序同一个name的表单怎么用serizelize()序列化呢,var paixu = $(":input[name='paixu']").serialize();用data:paixu,过去,只获取到最后一个排序。
回复讨论(解决方案)
<input type="text" name="test" value="t1"><input type="text" name="test" value="t2"><input type="text" name="test" value="t3"><input type="text" name="test" value="t4"><input type="submit" id="test" value="test"><script type="text/javascript">$("#test").click(function(){ var data; data = $(":input[name='test']").map(function(){ return $(this).val(); }).get(); alert(data);})</script>
<input type="text" name="test" value="t1"><input type="text" name="test" value="t2"><input type="text" name="test" value="t3"><input type="text" name="test" value="t4"><input type="submit" id="test" value="test"><script type="text/javascript">$("#test").click(function(){ var data; data = $(":input[name='test']").map(function(){ return $(this).val(); }).get(); alert(data);})</script>
这种方法我也可以实现,本来想试下用serialize()进行序列化,可没成功,用serialize()实现不了吗?
你要么遵守 php 的约定:同名对象用数组形式命名
要么从 file_get_contents('php://input') 取回数据自行解析
data:paixu,
paixu 要是一个json格式的数据,你序列化也不行啊
非要序列化可以这样
var data = $("#form").serialize();
$.ajax({
type: "post",
url:"xx.php",
data:{'data':data},
后台获取数据 $_POST['data']
回复:jam00,相同键值的name确实有点麻烦,还是遍历比较好用些吧,谢谢了
当然你也可以用 serializeArray
var paixu = {data : $(":input[name='paixu']").serializeArray() };
不过收到的是形如这样的数组
array(
'data' => array(
array('name' => 'paixu', 'value' => 1),
array('name' => 'paixu', 'value' => 2)
)
)

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

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

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

Alipay PHP...

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,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

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