weixin_33726318 2014-07-22 07:42 采纳率: 0%
浏览 35

带有POST和GET的AJAX调用?

这是Ajax的合法调用吗?我选择了$_get变量,而不是$_post。“Selected”是来自DataTable选择的数据数组。

   $.ajax({
        url: './inc/MediaScripts.php?argument=deleteRecords',
        type: 'POST',
        data: selected
    });

服务器端: print_r($GLOBALS);

[_GET] => Array
    (
        [argument] => deleteRecords
    )

[_POST] => Array
    (
    )

更新:

编辑后的JQuery:

        $.ajax({
            url: './inc/MediaScripts.php?argument=deleteRecords',
            type: 'POST',
            data: { "test1": "value1", "test2": "value2" }
        });

结果:

[_GET] => Array
    (
        [argument] => deleteRecords
    )

[_POST] => Array
    (
        [test1] => value1
        [test2] => value2
    )
  • 写回答

3条回答 默认 最新

  • weixin_33697898 2014-07-22 07:50
    关注

    I pick up the $_GET variable, but not the $_POST

    I think you should post an object instead:

    data: {selected : selected}
    

    On the server side you can pick this up with:

    $_POST['selected'] // it contains the array you posted.
    

    All in all i suggest you to stic with type:"post" and pass the vars like this:

    $.ajax({
        url: './inc/MediaScripts.php',
        type: 'POST',
        data: {argument:"deleteRecords", selected : selected}
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题