dougu5950 2012-11-10 02:12
浏览 42

在jQuery .post()中传递两个数组,如何在PHP中捕获这些数据并在那里使用它?

I'm making a jQuery .post() with the following arrays:

'cleanedLinkStructureArray[]': cleanedLinkStructureArray,
'cleanedPermaLinkArray[]': cleanedPermaLinkArray

The data inside these arrays: cleanedPermaLinkArray looks like this: ["2012","10","30","hello-world"] and cleanedLinkStructureArray like this: ["year","monthnum","day","postname"]

Javascript code:

var ajaxPost = $.post(
            enableAJAX.ajaxurl, 
            { action: 'ajaxRequest',
            'ajaxRequestNonce' : enableAJAX.ajaxRequestNonce,
            'cleanedLinkStructureArray[]': cleanedLinkStructureArray,
            'cleanedPermaLinkArray[]': cleanedPermaLinkArray },
            'json'
    );

    ajaxPost.done(function(responseText) { 
        alert(responseText);
        console.log(responseText);
    }); 

    ajaxPost.fail(function() { 
        alert("Oops, I'm afraid we've broken something");
    });

I don't understand how I catch the two arrays in PHP? and use the data from the arrays inside PHP? Preferably I would create new PHP array with them, where the values inside cleanedLinkStructureArray become the keys for the array and the values inside cleanedPermaLinkArray the values for that new array.

I guess it must be something with this, but I need someone more experienced to tell me what I need to do here.

$_POST['cleanedPermaLinkArray[]']
$_POST['cleanedLinkStructureArray[]']; 

Any help would be appreciated.

Kind regards,

Marnix

  • 写回答

3条回答 默认 最新

  • dongwu5743 2012-11-10 02:15
    关注

    This is all coming down from the server as JSON, right? Just use json_decode on the values and the'll be converted to arrays, natively inside of php.

    $cleanedPermaLinkArray = json_decode($_POST['cleanedPermaLinkArray[]']);
    echo cleanedPermaLinkArray[0]; // some value..
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog