Send data in json format to php

6

I know that sending json from PHP to JS is totally viable, but is it possible to send my data via json ajax to PHP?

    
asked by anonymous 18.12.2015 / 12:05

1 answer

9

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

The intent of the JSON format is to be universal. Although the JSON format is JavaScript syntax, it is read by other languages and is now the default for sending 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:

18.12.2015 / 12:07