gpt4 book ai didi

javascript - 如何通过AJAX传递表单值和个体值?

转载 作者:行者123 更新时间:2023-11-30 12:30:32 24 4
gpt4 key购买 nike

如何将表单值和用户 ID 传递给 ajax?

JavaScript:

jQuery("#DoneBtn").click(function(){
var data = $("#insertsubs_form").serialize();
<?php
$db = JFactory::getDBO();
$user = JFactory::getUser();
?>
var userid = <?php echo $user->id; ?>
$.ajax({
data: {
data:data,
userid : userid
},
type: "post",
url: "../insert_subs.php",
success: function(data){
alert(data);
}
});
});

在 insert_subs.php 中:

$userid = $_GET['userid'];

**** 感谢 Deena 的 Anand Patel。两者都是我想要的相同答案! :D 还要感谢 epascarello!我没有尝试过,但我认为它也能正常工作。 :)

最佳答案

试试这个

        jQuery("#DoneBtn").click(function(){

<?php
$db = JFactory::getDBO();
$user = JFactory::getUser();
?>
var userid = <?php echo $user->id; ?>;

var data = $("#insertsubs_form").serialize() + "&userid=" + userid;


$.ajax({
data: data,
type: "post",
url: "../insert_subs.php",
success: function(data){
alert(data);
}
});
})

关于javascript - 如何通过AJAX传递表单值和个体值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27853912/

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