gpt4 book ai didi

jquery - 将值传递给 ajaxform 数据

转载 作者:行者123 更新时间:2023-12-01 06:28:41 36 4
gpt4 key购买 nike

我想将变量的值传递给ajaxForm数据。

value1 = "dynamic_value1";
value2 = "dynamic_value2";
$('form').ajaxForm({
data: {
key1: value1,
key2: value2
}
});

期望类似:

date:{Key1:"dynamic_value1", Key2:"dynamic_value2"}

所以在 php 中我可以像这样访问

echo $_POST['key1'];

======================完整的脚本

<script src="../../bin/addons/jquery-1.7.2.js"></script>
<script src="../../bin/addons/jquery.form.js"></script>
<script>
// jQuery Form-plugin
(function() {
var value1 = "dynamic_value1";
var value2 = "dynamic_value2";
$('.dummyForm1').ajaxForm({
data:{
key1: value1,
key2: value2
}
complete: function(xhr) {
txt = xhr.responseText;
alert(txt);
}
});
})();
</script>

<form class="dummyForm1" action="form-php.php" method="post">
<input type="submit" value="Hit!" />
</form>

form-php.php

<?
echo "Key1 value:". $_POST['key1'];
?>

最佳答案

数据属性后面缺少一个逗号。

试试这个:

(function () {
var value1 = "dynamic_value1";
var value2 = "dynamic_value2";
$('.dummyForm1').ajaxForm({
data: {
key1: value1,
key2: value2
}, //You were missing this comma.
complete: function (xhr) {
txt = xhr.responseText;
alert(txt);
}
});
})();

关于jquery - 将值传递给 ajaxform 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11418319/

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