在Ajax中为PHP序列化数组 - php

我尝试序列化我的复选框项目。

首先,我想告诉你我想要什么。

我有这样的形式,

用户选择复选框,当按下按钮“ Sil”时,必须删除艺术家。

我为此准备了一个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,它具有这些数据。实际的问题是,ajax无法将此数据发送到php。我对此进行了一些研究,然后得出结论,我必须序列化我的阵列并添加我的$(".p16 input:checked").serialize()(function(){脚本进行序列化,但也无法正常工作。

public function deleteDataAjax2() {

        extract($_POST);

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

    }

上面的代码是我的PHP。并且artistIds始终为空,因此我的序列化功能不起作用。

可能是什么问题?我如何在php端获取我的artistIds?

编辑

最后,我来到这里

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

    }

还是错的

参考方案

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

这仍然为您提供了一组Artistid,因此您无法将其发送到服务器,您需要先将其转换为JSON格式,然后才能将其提交给服务器

$.post('/json/crewonly/deleteDataAjax2', JSON.stringify({ 'artistIds': artistIds }),function(response){
    if(response=='ok')
        alert("ok");
});

并确保在使用json_decode函数使用服务器上的json数据之前对其进行解码

PHP strtotime困境 - php

有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00�…

PHP-全局变量的性能和内存问题 - php

假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…

php-casperjs获取内部文本 - php

我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…

php:拆分字符串,直到第一次出现数字 - php

我有像cream 100G sup 5mg Children 我想在第一次出现数字之前将其拆分。所以结果应该是array( array('cream','100G'), array('sup','5mg Children') ); 可以告诉我如何为此创建图案吗?我试过了list(…

将大字符串分成多个小字符串-PHP - php

我从数据库中获取了一个长字符串,我需要对其进行解析,以使其不包含一个大字符串,而是多个,其中每个字符串都有2个字符。让我们以示例为例:我连接到表,获取此字符串:B1C1F4G6H4I7J1J8L5O6P2Q1R6T5U8V1Z5,之后,我必须对字符串进行解析,因此:B1 C1 F4 G6 H4 I7 J1 J8 L5 O6 P2 Q1 R6 T5 U8 V1…