0

Will this be a legitimate call for AJAX to handle? I pick up the $_GET variable, but not the $_POST. The 'selected' is a array of data from a dataTable selection.

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

Server side print_r($GLOBALS);

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

[_POST] => Array
    (
    )

.

Updated:

Edited JQuery

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

Result

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

[_POST] => Array
    (
        [test1] => value1
        [test2] => value2
    )
6
  • @AntoKing, funny... its the first sentence. (maybe why you say yes or no will be helpfull as-well).
    – morne
    Jul 22, 2014 at 7:44
  • I understand you have php on server side?
    – JNF
    Jul 22, 2014 at 7:46
  • Yes. sorry, should probably include that in the description down stairs.
    – morne
    Jul 22, 2014 at 7:46
  • ` I pick up...` I assume then you can see the call itself is working?
    – JNF
    Jul 22, 2014 at 7:49
  • 1
    You should be able to receive the data like that, have you tried to insert static data just to see if it works? for example: data: { "test1": "value1", "test2": "value2" }
    – UnTraDe
    Jul 22, 2014 at 7:50

3 Answers 3

2

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 :)

0
1

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}
});
6
  • Shouldn't he send the request using type: "POST" if he wants to read $_POST also?
    – UnTraDe
    Jul 22, 2014 at 7:51
  • I think he's trying to access both the POST & GET data.
    – Darren
    Jul 22, 2014 at 7:51
  • @Darren, Yes, I would like to know if exactly that is possible?
    – morne
    Jul 22, 2014 at 7:53
  • Sorry guys just misunderstood this, but as i understood now OP is able to pick up the var in url but not the array selected which is sent in ajax and that should be sent with a js object instead.
    – Jai
    Jul 22, 2014 at 7:53
  • @mornenel - Could you update your answer to show what selected looks like?
    – Darren
    Jul 22, 2014 at 7:55
0

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.

1
  • Sorry but this answer makes no sense what-so-ever. You're stating the obvious here..?
    – Darren
    Jul 22, 2014 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.