weixin_33694620 2014-06-02 11:59 采纳率: 0%
浏览 32

通过ajax传递数组

I'm fairly new to the jQuery execute on the same page stuff. So far I have been passing only single values trough ajax which is working fine. Now, I need to pass an array which is created by checkboxes through ajax.

My form html, dynamically created by php:

<input type=checkbox class=box name=box[] value=".$row['DoosID']." />

My jQuery:

    var BackorderDate   = $("#BackorderDate").val();
    var Box = $(".box").val();

        if( (TerugleverDatum == "") ){
            $("#backorderresult").html(" * Some Error .").fadeIn("Slow").fadeOut(3000);
        } else {
            $("#backorderresult").fadeOut();
            $.ajax({
                type    :'POST',
                url     :'./backorder.php',
                data    : box : Box,
                                              backorderdate: BackorderDate,
                dataType:"json",
                success: function(data){
                    // Do Something
             }
        });
    }

My PHP:

$boxlist = json_encode($box);

foreach($boxlist as $boxvalue){
   // Do something with every value
 }

this gives me a javascript error on submit saying box is not defined.

  • 写回答

4条回答 默认 最新

  • 笑故挽风 2014-06-02 12:04
    关注

    You might want to refer to the php file like this: url :'../backorder.php' (double dots). At least, that's how I do it always.

    评论

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用