douxia1988 2010-12-14 03:12
浏览 45
已采纳

使用$ .Post将JSON-ed数组传递给PHP

I have this code:

$("#sendData").click(function(e) {

// converts to JSON the array and returns a string.
var updateValues = JSON.stringify(dataArray); 

$.post("test.php", updateValues, function(data){
    document.write(alert)});
});

As you may see, is my intention to send a JSON array to test.php. Now in test.php i have something like:

<?php

    if(isset($_POST["updateValues"])) {
        echo $_POST["updateValues"];
    } else {
        echo "Error."
    }

?>

Now, i'm getting "Error". I believe it's because the array can not be passed just that way, even if it's JSON-ed. What's the correct way of passing arrays to PHP scripts?

  • 写回答

1条回答 默认 最新

  • dougui4325 2010-12-14 03:15
    关注

    Try...

    $.post("test.php", {'updateValues': updateValues}, function(data){
            alert(data);
    });
    

    You had a few syntax issues - and each post variable should have a key in the object to access it in PHP like that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题