发送通过AJAX多维数组 [英] Sending multidimensional array via ajax

查看:432
本文介绍了发送通过AJAX多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上这是我的jQuery和HTML $ C $下创建阵列。它基本上需要每个div带班的设置,并检查羯羊它与属性相对跨度,如果有,它插入数组下阵。每一个新的div.settign跨度相对属性将被插入到相同的父阵列在另一个数组。

So basically here is my jQuery and HTML code for creating arrays. It basically takes each div with class setting and checks wether it has span with attribute rel, if it has, it inserts in array under array. Each new div.settign span rel attributes will be inserted to another array under same parent array.

勾选此code去了解它 - http://jsfiddle.net/xVuHx/

Check this code to understand it - http://jsfiddle.net/xVuHx/ .

粘贴它也是在这里 -

Pasted it also here -

jQuery(document).ready(function() {
    var rel = [];
    jQuery(".setting").each(function() {
        rel.push(jQuery(this).find('span[rel]').map(function() {
            return this.getAttribute('rel');
        }).get());
    });               
    jQuery("body").text(rel);
});​

和HTML -

<div class="setting">
    <span rel="Variable">Variable</span>
    <span rel="Item">Item</span>
    <span rel="Something">Something</span>
</div>
<div>
    <span rel="Smth">Smth</span>
    <span>Sec</span>
</div>
<div class="setting">
    <span>Second</span>
    <span rel="first">First</span>
    <span rel="Third">Third</span>
</div>

它是伟大的工作,并显示两个数组 - 一个有3个元素,一个两个,但是当我尝试将它传递给通过AJAX的PHP文件,德州仪器给了我[对象的对象]用的var_dump($阵列); 。此外,我试图做的foreach,但它告诉我,无效的参数传递给foreach语句,所以我想我要送数组阿贾克斯不正确或阵列由不正确。

it's working great and displays two arrays - one with 3 elements and one with two, but when I try to pass it to PHP file via ajax, ti gives me [object Object] with var_dump($array); . Also I tried to do foreach, but it told me that invalid arguments were passed to foreach statement, so I guess I'm sending the array to ajax incorrectly or the Array is made incorrectly.

下面是我的ajax code -

Here is my ajax code -

var myArray = jQuery(this).sortable("serialize") + "&type="+rel+"&action=update_homepage";
jQuery.post("'.admin_url("admin-ajax.php").'", myArray, function(response){
   var info = response.slice(0,-1);
});

这阿贾克斯code通过字preSS而成,因此它的Ajax请求不同于默认AJAX请求一点点。

This ajax code is made via wordpress, so its ajax requests differs a little bit from default AJAX requests.

能否请你检查究竟可能是什么问题?

Could you please check what exactly could be the problem?

编辑:

只是试图输出的print_r($ myArray的); 在PHP端,它输出空字符串

Just tried to output with print_r($myArray); in php side, it outputs empty string.

推荐答案

在AJAX请求的浏览器控制台(部分网络)公布的数据格式检查

Check format of posted data in AJAX request in browser console (section network).

您可以找到有关<一打开控制台在您的浏览器信息href="http://webmasters.stackexchange.com/questions/8525/how-to-open-the-javascript-console-in-different-browsers">this stackexchange问​​题。

JSON-JS - JSON在JavaScript

JSON-js - JSON in JavaScript.

要的对象转换成JSON,使用 JSON.stringify

To convert an object to JSON, use JSON.stringify:

var json_text = JSON.stringify(your_object, null, 2);

恩code阵列以JSON然后将它与Ajax请求发送。要取消在PHP中code JSON使用 json_de code

这篇关于发送通过AJAX多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆