我嘗試序列化我的複選框項目。在Ajax中對php進行數組化處理
首先,我想告訴你我想要什麼。
我有一個這樣的形式,
用戶選擇checboxes當按下它的按鈕「實」移除藝術家。
我準備一個AJAX腳本,這是
function deleteData2()
{
var artistIds = new Array();
$(".p16 input:checked").serialize()(function(){
artistIds.push($(this).attr('id'));
});
$.post('/json/crewonly/deleteDataAjax2', { 'artistIds': artistIds },function(response){
if(response=='ok')
alert("ok");
});
}
我的AJAX腳本有電影ID和藝術家ID,它有這些DATAS。實際的問題是,ajax無法將這些數據發送到php。我做了一些研究,然後我達到了我必須序列化我的陣列並添加我的$(".p16 input:checked").serialize()(function(){
腳本序列化,但也不起作用。
public function deleteDataAjax2() {
extract($_POST);
if (isset($artistIds))
$this->sendJSONResponse('ok');
}
上面的代碼是我的PHP。和artistIds總是空的,所以我的序列化功能不起作用。
什麼可能是錯誤的?我怎樣才能達到我的藝術家在PHP方面?
編輯
最後,我來到這個
var artistIds = new Array();
$(".p16 input:checked").each()(function(){
artistIds.push($(this).attr('id'));
});
$.post('/json/crewonly/deleteDataAjax2', JSON.stringify({ 'artistIds': artistIds }),function(response){
if(response=='ok')
alert("ok");
});
,並在PHP端,
public function deleteDataAjax2() {
extract($_POST);
$a = json_decode($artistIds);
if (!empty($a))
$this->sendJSONResponse('ok');
}
它仍然是錯誤的
你能給出$ _POST變量的數據嗎? – 2012-03-24 22:04:19