[英]How to get Input value 1 by 1 from jquery to PHP
<script type="text/javascript">
// index.php
function get(){
$('#age').hide();
$.post('data.php',{ name: $('form').serialize() },
function (output){
$('#age').html(output).fadeIn(1000);
});
}
</script>
<body>
<form name="form" action="a.php">
<input type="text" name="name[]" value="1"/>
<input type="text" name="name[]" value="2"/>
<input type="button" value="Get" onclick="get();"/>
</form>
<div id="age">
</div>
but result show 但是结果显示
Array ( [name] => name%5B%5D=1&name%5B%5D=2 )
I want to get 1 by 1 value. 我想得到1乘1的值。 so that I can collect data from database running a query to based on value please, kindly help me
这样我就可以从运行查询的数据库中收集基于值的数据,请帮我
data.php: data.php:
<?php //data.php
echo "<pre>";
print_r($_POST);
echo "</pre>";
?>
This approach only works when you POST the form normally, using submit. 仅当使用提交正常发布表单时,此方法才有效。
You now need to unserialize the data: 现在,您需要反序列化数据:
<?php
var_dump(unserialize($_POST['name']));
?>
This line 这条线
$.post('data.php',{ name: $('form').serialize() },
Says that you post your form (serialized) as the value of key 'name'. 说您将表单(序列化)发布为键“名称”的值。 While this is possible, I presume you just want your values.
尽管这是可能的,但我想您只是想要您的价值观。
If you take a quick look over at the jquery post manual youc an see that you can make an object like this: 如果快速浏览一下jquery帖子手册,就会发现您可以制作一个这样的对象:
{ name: "John", time: "2pm" }
Just read your form-values with jquery and put them in an object like that, instead of serializing the form. 只需使用jquery读取表单值,然后将其放入类似的对象中,而不是序列化表单即可。
I'm not sure if I understand your question, but I'm guessing you're not receiving the correct value in your php file? 我不确定我是否理解您的问题,但是我猜您在php文件中没有收到正确的值?
Try this -- In your HTML file, use this: 尝试以下操作-在HTML文件中,使用以下命令:
<script type="text/javascript">
// index.php
function get()
{
$('#age').hide();
$.post('data.php',
{
"name1":$('#name1').val(),
"name2":$('#name2').val()
},
function (output){
$('#age').html(output).fadeIn(1000);
});
}
</script>
<body>
<form name="form" action="a.php">
<input type="text" name="name1" id="name1" value="1"/>
<input type="text" name="name2" id="name2" value="2"/>
<input type="button" value="Get" onclick="get();"/>
</form>
and in your php page, have this: 并在您的php页面中,执行以下操作:
<?php
echo "<pre>";
echo "this is the first input: " . $_POST['name1'] . "<br />";
echo "this is the second input: " . $_POST['name2'] . "<br />";
echo "</pre>";
?>
Hope I interpreted your question correctly. 希望我能正确解释你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.