如何发送数组的数组作为$就数据()? [英] How to send array of arrays as data in $.ajax()?

查看:157
本文介绍了如何发送数组的数组作为$就数据()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经被问过很多次,但没有人帮助我。 我想为数组传递通过使用$阿贾克斯数据的数组(这可能会或可能不会有数组本身)()。数据发送(ACC到code在PHP)从服务器接收的响应应该是相同的,但它发送空白的对象。 请帮帮我知道通过这样的一个数组的正确的语法。

I know this question has been asked before many times but none of them helped me. I am trying to pass an array of arrays(which may or may not have arrays in themselves) through data using $.ajax(). The response received from the server should be the same as data sent (acc to the code in php) but it sends blank object. Please help me knowing the correct syntax of passing such an array.

val_pass是一个数组的数组和#display_message是款追加上。在这里,我去code:

val_pass is an array of arrays and #display_message is paragraph to append on. Here goes my code:

 $.ajax({
        type: 'POST',
        url: 'http://someurl.com/',
        // data: JSON.stringify(val_pass),
        // data: JSON.stringify({paramName: val_pass}),
        // data: {'myArray': val_pass},
        // data: $.toJSON(val_pass),
        data: {val_pass: val_pass},
        // data: $.serialize(val_pass),
        success: function(response){
            console.log(response);
            $('#display_message').append('Data successfully passed');
        },
        error: function(xhr, status, errorThrown){
            console.log(xhr+status+errorThrown);
            alert("Sorry");
        },
    });

PS:注释行有不同的方法,我想传递一个数组。我是新来的阿贾克斯请忽略我的noobness。

PS: commented lines are various ways i tried to pass an array. I am new to ajax please ignore my noobness.

推荐答案

我的问题的解决方案。 中首先强似数组的数组,我把它作为一个对象数组。

I got the solution for the problem. Firstly instead of passing arrays of arrays, I sent it as an array of objects.

现在我val_pass是对象的数组code:

Now my val_pass is array of objects.Code:

var jObject={};
jObject = JSON.stringify(val_pass);

$.ajax({
    type: 'POST';
    data: {jObject: jObject};
    url: some_url;
});

<一个href="http://pavanarya.word$p$pss.com/2012/09/09/calling-a-webservice-using-jquery-and-passing-jsonarray-object/" rel="nofollow">http://pavanarya.word$p$pss.com/2012/09/09/calling-a-webservice-using-jquery-and-passing-jsonarray-object/

提及此链接寻求帮助。

这篇关于如何发送数组的数组作为$就数据()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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