Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php read json request body

//e.g your JSON Req is like this {"UserName":"Ranish","Password":"asdasdasd"}
$jsonReqUrl  = "php://input";
$reqjson = file_get_contents($jsonReqUrl);
$reqjsonDecode = json_decode($reqjson, true);
echo $reqjsonDecode['UserName'];
Comment

php json request get value

<?php
$jsonurl = "https://reqres.in/api/users/2";
$json = file_get_contents($jsonurl);
$jsonDecode = json_decode($json, true);
echo $jsonDecode['data']['email'];
?>
Comment

php return json data

header('Content-Type: application/json'); 

$colors = array("red","blue","green");
echo json_encode($colors);
Comment

php return a json response

//PHP File
<?php
$data = /** whatever your data are **/;
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);

//In JS File
//JQUERY AJAX
        $.ajax({
        url: "path/to_php_file.php",
        dataType: "json",  
        type: "GET",
        data: {datax : datax },
Comment

PREVIOUS NEXT
Code Example
Php :: SSL PHP CURL 
Php :: get the unique rows from table laravel 
Php :: laravel loop through collection 
Php :: get cart item by cart item key woocommerce 
Php :: convert number to 2 decimal places in php 
Php :: yii2 get action class in view 
Php :: php guzzle client x-www-form-urlencoded 
Php :: laravel get fillable attributes 
Php :: laravel new project command 
Php :: php pdo Check if row exists in the database 
Php :: HTML Snippets not working in .php files 
Php :: Laravel - create model, controller and migration in single artisan command 
Php :: php check if folder empty 
Php :: filemtime($current_file_name); 
Php :: read text from docx in php 
Php :: laravel if file is image 
Php :: How to get only year, month and day from timestamp in Laravel 
Php :: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in 
Php :: laravel append to model 
Php :: diff for seconds laravel carbon 
Php :: run composer with different php version 
Php :: convert a php array into a javascript array 
Php :: laravel blade route redirect back 
Php :: create user with tinker php laravel 
Php :: php key value dictionary 
Php :: laravel gigapay 
Php :: symfony get query param 
Php :: date to string in php 
Php :: unable to locate package php8.1 ubuntu 
Php :: loop object property laravel 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =