gpt4 book ai didi

PHP JSON 数据传递

转载 作者:行者123 更新时间:2023-12-01 01:21:48 27 4
gpt4 key购买 nike

我有一个像这样的html html

<input type="checkbox" class="pushchecks" value="JAN" >
<input type="checkbox" class="pushchecks" value="FEB" >
<input type="checkbox" class="pushchecks" value="MAR" >

我需要获取选中的复选框值并以JSON格式传递到另一个页面

JQUERY

$('body').on('click','.pushchecks',function(){           
var bills = {}; var i=0;
$(".checks:checked").each(function(){ bills = $(this).val(); i++; });
bills = JSON.stringify(bills);
$.load('process.php', { checkedbills:bills }, '.list',function(){});
});

流程.php

 $billsAry  =   json_decode($_REQUEST['checkedbills']); 

如果我选中 JAN 和 MAR 复选框,那么我需要在 process.php 页面中显示 JAN 和 MAR

最佳答案

只需对 Louys Patrice Bessette 代码进行一些编辑即可实现此功能。请注意,这里的请求是 POST request

test.html

<input type="checkbox" class="pushchecks" value="JAN" >
<input type="checkbox" class="pushchecks" value="FEB" >
<input type="checkbox" class="pushchecks" value="MAR" >

<!--to readable output from the php file-->
<pre class="result"><pre>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$('body').on('click','.pushchecks',function(){
// An array.
var bills=[];

// Loop trought all .pushchecks checked.
// Edited to be .pushchecks instead of .checks
$(".pushchecks:checked").each(function(){

// Add this value in array.
bills.push( $(this).val() );
});

// Stingify the array. Would convert the array to json object
bills = JSON.stringify(bills);

// Ajax request to load process.php result in the pre tags above.
// Use $('*') to select all elements in the DOM
$('.result').load('process.php', { checkedbills:bills }, '.list',function(){});
});
</script>

process.php

<?php

$billsAry = json_decode($_REQUEST['checkedbills']);
print_r($billsAry); //The response and output to the request
?>

关于PHP JSON 数据传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44486071/

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