我正在尝试使用ajax将数组从javascript发送到PHP脚本。这是我到目前为止的代码。
<?php
$i = 1;
while (++$i <= $_SESSION['totalcolumns']) {
$range = $_SESSION["min-column-$i"] . ',' . $_SESSION["max-column-$i"];?>
<br><?php echo "Keyword" ?>
<?php echo $i -1 ?>
<br><input type="text" data-slider="true" data-slider-range="<?php echo $range ?>" data-slider-step="1">
<?php } ?>
<button type="button" >Update</button>
<script>
$("[data-slider]")
.each(function () {
var range;
var input = $(this);
$("<span>").addClass("output")
.insertAfter(input);
range = input.data("slider-range").split(",");
$("<span>").addClass("range")
.html(range[0])
.insertBefore(input);
$("<span>").addClass("range")
.html(range[1])
.insertAfter(input);
})
.bind("slider:ready slider:changed", function (event, data) {
$(this).nextAll(".output:first")
.html(data.value.toFixed(2));
});
$(".output")
.each(function() {
var parms = [];
parms.push($(this).text());
});
</script>
<script>
function loadXMLDoc()
{
$.ajax({
type: "POST",
url: "update.php",
data: { value : $(parms).serializeArray() },
success: function(data)
{
console.log (data);
}
});
}
$("button").on('click',function(){ loadXMLDoc(); });
</script>
在我的 $。output 函数中,我使用 parms [] 数组来存储我尝试传递给下一个PHP的所有UI滑块值 loadXMLDoc()函数中定义的按钮单击事件上的脚本页面。在我的PHP页面中,我正在访问它们,如下所示。
<?php
$uid = $_POST['value'];
echo "Am I getting printed";
echo $uid;
// Do whatever you want with the $uid
?>
但是,我无法在update.php脚本中查看数据。有人可以让我知道我做错了什么吗?
到目前为止,这是我工作的link。
答案 0 :(得分:0)
serializeArray返回json对象,也许你可以在php脚本中尝试json_decode,就像:
$uid_arr = json_decode($uid,true);
print_r($uid_arr);
答案 1 :(得分:0)
只需使用
data: $(parms).serializeArray()