-2

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?

spooky655
  • 99
  • 2
  • 10

3 Answers3

0

you probably want to send the result from json_encode() to another server in PHP via POST.

see How do I send a POST request with PHP?

Community
  • 1
  • 1
dreamlab
  • 3,321
  • 20
  • 23
0

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" }
        });
Vivek Pratap Singh
  • 9,326
  • 5
  • 21
  • 34
0

I avoided the issue by keeping the php code in the same file as I am receiving the array.

spooky655
  • 99
  • 2
  • 10