gpt4 book ai didi

php - Serialize() 输出与数据字符串相同但不作为ajax数据值工作

转载 作者:行者123 更新时间:2023-11-28 02:02:52 24 4
gpt4 key购买 nike

我已经设置了一个包含 4 个输入字段的表单(登录名、电子邮件、密码、再次密码),当我单击提交时,它会验证输入并将其发送到 process-register .php 通过 GET

现在,当我使用 data 变量作为 ajax 数据时,问题就来了,它一切正常,但如果我使用 $("form").serialize () 它不再起作用了...

编辑:它不会将变量传递给process-register.php

我已经用 document.write 输出了两个字符串,它们完全相同!这怎么可能?!请帮我解决这个问题...

var data = 'login=' + login.val() + '&email=' + email.val() + '&pass=' + pass.val() + '&confirmpass='  + confirmpass.val();

//document.write($("form").serialize()); --> The output is
//document.write(data); --> exactly the same! :O

$('input').attr('disabled','true');

$('.loading').show();

$.ajax({
url: "process-register.php",

type: "GET",

data: data, //--> works!
data: $("form").serialize(), //--> doesn't work!

cache: false,

success: function (echo) {
//success code...
}
});

最佳答案

将行 $('input').attr('disabled','true'); 移至序列化数据之后。
就像下面这样。

var data  = $("form").serialize();
$('input').attr('disabled',true);

$.ajax({
url: "process-register.php",
type: "GET",
data: data
});

来自 API 文档 ( http://api.jquery.com/serialize/ )

Note: Only "successful controls" are serialized to the string. No submit button value is serialized since the form was not submitted using a button. For a form element's value to be included in the serialized string, the element must have a name attribute. Values from checkboxes and radio buttons (inputs of type "radio" or "checkbox") are included only if they are checked. Data from file select elements is not serialized.

它也不会序列化禁用控件

关于php - Serialize() 输出与数据字符串相同但不作为ajax数据值工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18217333/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com