Send data in json format to php

Asked

Viewed 954 times

6

I know it is fully feasible to send PHP json to JS, but it is possible to send my data via ajax in json format to PHP?

  • 4

    Yes it is possible.

1 answer

9


Yes, it is possible to send data via ajax in json format to PHP.

The intention of the JSON format is to be universal. Although the JSON format is Javascript syntax, it is read by other languages and is today the default to send data.

From Javascript to PHP:

var json = JSON.stringify(dados);

and in PHP:

$dados = json_decode($json);

From PHP to Javascript

$json = json_encode($dados);

and in Javascript:

var dados = JSON.parse(json);

More reading:

  • 2

    Thank you, you helped me a lot.

  • But how to send json to php?

  • @Neo take a look here: http://answall.com/a/20920/129

Browser other questions tagged

You are not signed in. Login or sign up in order to post.