2012-03-23 167 views
1

我尝试从ajax发送一些数据到我的php文件,但我无法成功。 这是我的ajax文件,为什么我无法获得ajax值?

var artistIds = new Array(); 

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


    $.post('/json/crewonly/deleteDataAjax2',artistIds,function(response){ 
     if(response == 'ok') 
      alert('error'); 
     else 
      alert('nop'); 
    }) 

,并在PHP端我用这个代码

extract($_POST); 

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

$ artistIds总是与空 为什么为什么为什么

最后我来到了这一点,但也不起作用

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'); 
    });* 
+0

SRY ......监督你的提取物() – 2012-03-23 17:58:32

+0

$ artistIds是一个数组是的,但它是空的 – user1277467 2012-03-23 17:59:52

+0

叶氏其empyt在PHP端,为什么:S – user1277467 2012-03-23 18:00:40

回答

0

你需要传递一个对象以值与名字相关联。

var data = { 
    artistIds: artistIds //Here, the property name is "artistIds", which is going to be the name of your PHP variable. Your JS variable is also called that. 
}; 

$.post('/json/crewonly/deleteDataAjax2',data,function(response){ 
//... 
0

做你的$。员额是这样的:

$.post('/json/crewonly/deleteDataAjax2', { artistIds: artistIds }, ...); 
+0

我编辑它请看看 – user1277467 2012-03-23 18:11:34

+0

在查看文件后,我认为你应该写它如下:'$ .post('/ json/crewonly/deleteDataAjax2',{'artistIds []':artistIds}, ....)'。但我不太确定 – 2012-03-23 18:15:20

相关问题