D
D
Dark192017-06-12 12:43:01
PHP
Dark19, 2017-06-12 12:43:01

How to convert an array to json and get the same array in php?

Hey! There have already been a lot of things on this topic, but I'm already confused and tried to solve the problem in different ways, but it doesn't work. In general, there is an array and this is ajax:

var cat = ["flats", "underground", "houses"];
        var post_type = $(this).data('post-type');

        $.ajax({
            type : "post",
            context: this,
            dataType : "json",
            url : ajaxurl,
            data : {
                action: "filter_hobby",
                post_type: post_type,
                post_term: JSON.stringify($.extend({}, cat))
            },
            beforeSend: function(data) {
                $('.areas').css('opacity', '1');
            },
            success: function(response) {
                var $newElems = $(response.html);
                $('.areas').html($newElems);

                $('.areas').css('opacity', '1');
            }
        });

Converted to jquery and received in php, but I just can not achieve the desired result.
In php I do like this: But not that, I need the same array ["flats", "underground", "houses"] as output in php. Tell me how to do it? json_decode($_REQUEST['post_term'])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-06-12
@Dark19

post_term: cat
instead of
post_term: JSON.stringify($.extend({}, cat))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question