0

I try to send my data to php file but does not work. This my ajax file

 var artistIds = new Array();

    $(".p16 input:checked").each(function(){
        artistIds.push($(this).attr('id'));
    });


   $.post('/json/crewonly/deleteDataAjax2', { artistIds: artistIds },function(response){
        if(response == 'ok')
            alert('dolu');
        elseif (response == 'error')
            alert('bos');
    });

and this is my php

public function deleteDataAjax2() {

        extract($_POST);

        if (isset($artistIds))
            $this->sendJSONResponse('ok');
        else
            $this->sendJSONResponse('error');
    }

However, my artistIds in php side is null. Why ?

  • Add `var_dump($_POST)` to your `deleteDataAjax2` to see exactly what you're getting. – gen_Eric Mar 23 '12 at 19:24
  • What does `sendJSONResponse` echo? – gen_Eric Mar 23 '12 at 19:28
  • 1
    [How to pass a Javascript Array via JQuery Post so that all its contents are accessible via the PHP $_POST array?][1] [1]: http://stackoverflow.com/questions/5571646/how-to-pass-a-javascript-array-via-jquery-post-so-that-all-its-contents-are-acce – Anas Al Hamdan Mar 23 '12 at 19:28

1 Answers1

0

You cannot pass an array without serializing the values first.

See: How to send js array via ajax?

Community
  • 1
  • 1
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
  • This is wrong. Passing `{IDs: [1,2,3]}` to `$.post` will send `IDs[]=1&IDs[]=2&IDs[]=3` as the query string, thus making it an array when read by PHP. – gen_Eric Mar 23 '12 at 19:24
  • Please see => http://stackoverflow.com/questions/5571646/how-to-pass-a-javascript-array-via-jquery-post-so-that-all-its-contents-are-acce – gen_Eric Mar 23 '12 at 19:29