doutui9606 2016-08-21 06:33
浏览 37

我不能从JavaScript传递变量到PHP并且jQuery加载响应

I want passing 2 parameters to PHP page via AJAX and load the response, but this code is not working.

JavaScript:

$(".show_category").click(function(){
    var category_id = $(this).attr('data-category');
    $.ajax({
        url: "conx.php",
        method: "POST",
        data: {
            action: "sort_category",
            category_id: category_id
        },
        success: function(data) {
            $("#con").load("conx.php");
        }
    });
});

PHP:

<?php
    echo "1".$_POST["action"]."<br/>";
?>
  • 写回答

1条回答 默认 最新

  • drutcs7210 2016-08-21 06:40
    关注

    You issue is here:

        success: function(data) {
            $("#con").load("conx.php");
        }
    

    At this point, you have already posted the data and received the HTML response. There is no need to make another HTTML request by calling .load, and doing so will mean requesting it again without the POST data, so it will not have the intended effect. Just use the HTML you already have in the data argument.

        success: function(data) {
            $("#con").html(data);
        }
    

    On a side note, this PHP code is a reflected XSS vulnerability:

    <?php
        echo "1".$_POST["action"]."<br/>";
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀