weixin_33681778 2018-02-12 19:51 采纳率: 0%
浏览 31

PHP数组提交给ajax

I'm not sure if this question has been asked before, so please note if it's duplicate.

The top line is a PHP merged array that I'm trying to send in AJAX to another page.

I'm having trouble finding what goes in the "?" or how to format it.

<?php $_SESSION['pdfData'] = array_merge_recursive($count, $qty); ?>

$.ajax({ 
    type: "POST",
    url: "indexMenu-sm-pdf.php",
    data: { 
            ? 
        },
    dataType: "JSON", 
    success: function(data){
        console.log("Good.");
    },
        error: function(jqXHR, textStatus, errorThrown) {
        console.log(textStatus, errorThrown);
    } 
});

I understand that the built-in function json_encode() but i lack the know-how. And I've been reading about serialization. Is one better than the other?

My main questions are:
What goes into the "?" as $_Session['pdfData'] can not be sent.
And
Is there a difference is using json_encode vs. serialization for this issue?

</div>
  • 写回答

2条回答 默认 最新

  • weixin_33675507 2018-02-12 20:15
    关注

    It should be something like this:

    $.ajax({ 
        type: "POST",
        url: "indexMenu-sm-pdf.php",
        data: { 
                paramName: <?php echo json_encode($_SESSION['pdfData']) ?>
            },
        dataType: "JSON", 
        success: function(data){
            console.log("Good.");
        },
            error: function(jqXHR, textStatus, errorThrown) {
            console.log(textStatus, errorThrown);
        } 
    });
    

    Replace paramName with the name of the $_POST parameter that indexMenu-sm-pdf.php is expecting to get the PDF data from. json_encode() will output the contents of the session variable in the form of a Javascript literal.

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘