weixin_33722405 2014-07-23 14:01 采纳率: 0%
浏览 11

发布变量未通过

Any idea why this doesn't work? I have tried to see if the button clicked actually works with alerts, had alerts as well as before and after the ajax code and they both worked.

var selectedCheckboxes = "12421";

jQuery(document).ready(function($){
                $(".editArticle").on("click",function(){
                    $.ajax({
                        url: "test.php",
                        type: "POST",
                        data: { selectedCheckboxes: "selectedCheckboxes" },
                        success: function(response){
                              //do action  
                        },
                        error: function(){
                              // do action
                        }
                    });
                });
            });

the link:

 <a href="test.php" class="editArticle">Edit</a>

test.php

<?php
echo $_POST["selectedCheckboxes"];
?>
  • 写回答

5条回答 默认 最新

  • bug^君 2014-07-23 14:06
    关注

    You try to pass a variable selectedCheckboxes but unfortunately with double ("") quotes you passing a string as selectedCheckboxes

    Use below code

    var selectedCheckboxes = "12421";
    
    var dataObject = {};
    data[selectedCheckboxes] = 1;
        jQuery(document).ready(function($){
                    $(".editArticle").on("click",function(){
                        $.ajax({
                            url: "test.php",
                            type: "POST",
                            data: dataObject ,
                            success: function(response){
                                  //do action  
                            },
                            error: function(){
                                  // do action
                            }
                        });
                    });
                });
    

    Hope this helps...

    评论

报告相同问题?

悬赏问题

  • ¥15 电脑键盘实现触摸功能
  • ¥25 matlab无法将表达式转换为双数组怎么解决?
  • ¥15 单片机汇编语言相关程序
  • ¥20 家用射频美容仪技术规格
  • ¥15 大家帮我看看为什么错了
  • ¥15 unity互动琴弦抖动效果
  • ¥15 做了个的二极管反向饱和电流测量电路,但是测试达不到效果
  • ¥15 nginx无证书访问https失败
  • ¥15 树莓派启动AP热点传入数据
  • ¥15 multisim中关于74ls192n和DSWPK开关的问题(相关搜索:计数器)