使用AJAX检索的PHP文件序列数据称为 [英] Retrieving serialize data in a php file called using ajax
本文介绍了使用AJAX检索的PHP文件序列数据称为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
表格发送Ajax code:
VAR海峡= $(形式)序列化();
警报(STR);
// VAR UNS = @反序列化(STR);
//警报(UNS);
$阿贾克斯({
键入:POST,
网址:update.php
数据:BOX1 =+海峡,
成功:函数(值)
{
$(#数据)HTML(值);
}
HTML表单
<形式GT; <输入类型=复选框名称=盒[]值=1/><输入类型=复选框名称=盒[]值='2'/> < /形式GT;
在我的PHP
$箱= $ _ POST ['BOX1'];
如何进入每个盒子变量值在PHP端。
解决方案
您的js应该是这样的:
VAR海峡= $(形式)serializeArray()。
$阿贾克斯({
键入:POST,
网址:update.php
数据:海峡,
成功:函数(值){
$(#数据)HTML(值);
}
});
使用PHP,您应该循环的结果数组。
$箱= $ _ POST ['盒子'];
的foreach($箱为x $){
回声$ X;
}
编辑: 你必须使用serializeArray功能jQuery中。然后,它会与此code。
Form sending Ajax code:
var str = $("form").serialize();
alert(str);
// var uns=@unserialize(str);
//alert(uns);
$.ajax({
type: "POST",
url: "update.php",
data: "box1="+str,
success: function(value)
{
$("#data").html(value);
}
Html Form
<form> <input type=checkbox name=box[] value='1'/><input type=checkbox name=box[] value='2'/> </form>
IN My Php
$box=$_POST['box1'];
How to access the each of the box variable values in php side.
解决方案
Your js should be like this:
var str = $("form").serializeArray();
$.ajax({
type: "POST",
url: "update.php",
data: str,
success: function(value) {
$("#data").html(value);
}
});
With php you should loop your result array.
$box = $_POST['box'];
foreach ($box as $x) {
echo $x;
}
Edit: You have to use serializeArray function in jQuery. Then it will work with this code.
这篇关于使用AJAX检索的PHP文件序列数据称为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文