Sending an associative array of PHP via ajax to PHP

advertisements

I am receiving an associative array from PHP via $_GET through the following url: example.com/example.php?itemcount[A]=2&itemcount[B]=3

The result of using json_encode() is the following: { "A" : "2", "B" : "3" }

I want to send this to another php file via ajax. How can I do this?

EDIT: I additionally want to send other variables such as through data: {"var1" : "val1", "var2" : "val2", "var3" : "val3" }.

How can I send all of these?


I think you are looking for this:

  $.ajax({
            url: '/path/hello.php',
            type: 'post',
            dataType: 'json',
            success: function (data) {
               //your code here..
            },
            data: jsonDataVar   //jsonDataVar = { "A" : "2", "B" : "3" }
        });