dsfsdf7852 2010-07-26 09:54 采纳率: 100%
浏览 86
已采纳

使用jquery发送数组

i have a variable $visitRecord->getReferallist() which get the list of doctors in an array . i need to send the array to a php file and do foreach action in php file.. how do i send this array variable in the jquery . This code did not work.

 function seekOpinion()
    {
    var queryUrl = "<?php echo $this->url(array('controller' => 'consultant', 'action' =>'opiniondoclist'));?>";
    $.post(queryUrl,{referal:'<?php echo $gotreferal; ?>',visitId:'<?php echo $gotvisitId; ?>',referalList:'<?php echo $visitRecord->getReferallist(); ?>'},function(data)
    {
            $('.opiniondoclistData').html(data);
    });
            document.getElementById('opiniondoclistDiv').style.display = "";
    }
  • 写回答

6条回答 默认 最新

  • duanjue6584 2010-07-27 08:47
    关注

    Your problem is that you're working with an Array in PHP.

    echo $visitRecord->getReferallist(); // Returns array of referrals.

    When you cast the array to a string by echo'ing it (because echo outputs strings) then you get the text "Array".

    In order to send this over the wire(from javascript via AJAX ($.post)) you will need to convert your referral list into a string. One method is serialization. You can convert your array into a "stringable format" using the serialize() function. www.php.net/serialize.

    When this is received from PHP in the AJAX request you can convert your "stringable formatted" array back into a pure array using the unserialize() function. www.php.net/unserialize.

    Your code should change from

    $visitRecord->getReferallist();

    to

    serialize($visitRecord->getReferallist());

    Then when it's received you should change your code from

    $referrals = $_POST['referalList']; // Stringable version of the array

    to

    $referrals = unserialize($_POST['referalList']); // Pure PHP array

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)