带有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
    )

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}
});

Any data passed in the URL queryString can be accessed with $_GET, even if you use POST to submit the data, but the 'data' ('selected' array) can only be read in the $_POST variable.

the data property should look something like this data: {"selected": selected}

other than that if the url is correct just try something like this

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

and see for yourself :)