M
M
Maxim Timofeev2015-11-13 16:20:25
JavaScript
Maxim Timofeev, 2015-11-13 16:20:25

How to pass nested array via ajax?

there is an array in php with a nesting of the form:

[
'f1' => 'ssss',
'f2' => 'sss2'
'f' => [
'11'=>'ww',
'www'=>'wcec'
]
]

I have an ajax request:
$.post(
      url,
      {f1:'ww',f2:'ww'},
      function(data){
         // тут не важно
      }
);


How to form data from an array for ajax in jquery? It flipped over thoroughly. jquery is output by the php script, so it can be inserted as a variable, but how?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ilya Beloborodov, 2015-11-13
@webinar

<?php 
     $arr=[
        'f1' => 'ssss',
        'f2' => 'sss2',
        'f' => [
            '11'=>'ww',
            'www'=>'wcec'
        ]
    ];

    echo json_encode($arr);

it turns out
{"f1":"ssss","f2":"sss2","f":{"11":"ww","www":"wcec"}}

M
Mikhail, 2015-11-13
Chirskiy @chirskiy_mixail

Normally serialize() on the form does this for you, but in AJAX just pass serialize as parameters

V
Vladimir, 2015-11-13
@Vovchikvoin

On php json_encode

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question