gpt4 book ai didi

javascript - 在 JS 中序列化输入,在 php 中返回字符串

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

我的 JS 代码有一些问题。

我有一个 AJAX,我想在 PHP 中获取变量。

除了“param”数据之外,一切正常。

这是代码:

$('#signup_submit').click(function (event){
param = jQuery('input').filter(function() {
return this.name.match(/param/);
}).serialize();
event.preventDefault();
$.ajax({
type: "POST",
url: result.php,
data: {
action: 'submit_ajax',
email: $('#email').val(),
send_welcome: true,
listId: $('#listid').val(),
param: param
},
success: function(msg) {
console.log('ok');
}
});
});

参数的结果 var_dump (PHP):

 param%5Bconfirmation%5D=1

应该是这样的:

array(1){ 'confirmation'=>1 }

有解决办法吗?

谢谢

最佳答案

您发布的 $param var 看起来像 param[confirmation]=1

并且您需要 parse_str 函数来获取序列化数据:

parse_str($param, $output);

输出

var_dump($output);

array(1) {
["param"]=>
array(1) {
["confirmation"]=>
string(1) "1"
}
}

或者直接获取具体索引:

parse_str($param);
echo $confirmation; // 1

关于javascript - 在 JS 中序列化输入,在 php 中返回字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24294156/

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