Receive json post in php from browser

I am trying to receive and print json with this php code:

<?php $data = json_decode(file_get_contents('php://input'), true); print_r($data); ?>

I am not receiving or printing any data. But if i use this ajax:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script> <script> (function($){ function processForm( e ){ $.ajax({ url:'http://mydyndns:8010/has/input_parameters_startReg.php', dataType: 'json', type: 'POST', contentType: 'application/json', data: JSON.stringify({ DeviceID: 23, ForceReg: 0, StartTime: "10/06/2015 17:45"}), success: function (data) { }, error: function (e) { alert(e.responseText); }, }); e.preventDefault(); } $('#my-form').submit( processForm ); })(jQuery);

it is working, and i get the posted data printed in my browser. How can i alter my php so the direct hitting from browser will give me the result the ajax gives?

--------------Solutions-------------

Function parse_str will do the job in combination with $_SERVER['QUERY_STRING']

<?php
parse_str($_SERVER['QUERY_STRING'], $output);
$json = json_encode($output);
echo $json;
?>

I don't think you'll be able to fetch it using GET because php://input seems to only read POST data. If you want to be able to use the GET data, you can refer to the $_GET global:

print_r($_GET);

Note that you can also use $_POST in place of php://input, but here's a question/answer on here that talks about that some:

PHP "php://input" vs $_POST

EDIT: Oops, I see this was answered while I was taking my sweet time.

Category:php Time:2018-11-06 Views:0
Tags: php json post

Related post

  • Jquery ajax json post to php variable 2011-07-19

    I am looping through a mysql table and printing an HTML "Play" link for each row. I'm trying to avoid refreshing the page on every click of the 'Play' link so I'm placing javascript in the link's 'href': <a href='javascript:void(0)' onclick='playM

  • JSON Post To Rails From Android 2011-11-26

    I'm currently working on an android app that interfaces with a Ruby on Rails app through XML and JSON. I can currently pull all my posts from my website through XML but I can't seem to post via JSON. My app currently builds a JSON object from a form

  • how to start an aws instance using php from browser 2012-01-26

    When I try to execute php file from browser which have a command to start AWS ec2 instance I am getting error as ec2start command not found, but when I execute this file from command prompt in Ubuntu it works fine as I am executing this as a root but

  • Decoding JSON feed via PHP from Twitter not working? 2010-01-26

    So I'm pulling down a user's tweet steam in JSON format via PHP. I'd like to decode it into an associative array or at least some more usable fashion rather than a string so that I can maneuver through it. I've been reading like mad about json_decode

  • Issue reading HTTP request body from a JSON POST in PHP 2011-08-13

    I'm writing a script that is registered as an endpoint for a webhook. I know that it's successfully registered because I'm writing the header of every request to my server logs. Here's a sample: Content-Type: text/xml; charset=UTF-8 User-Agent: Jakar

  • how to get JSON response in php from Facebook 2010-08-17

    I want to receive the JSON Response from (Facebook) https://graph.facebook.com for further processing in PHP. How can I access the JSON --------------Solutions------------- I am not sure if its really an amateur question, be it so the answer is : If

  • Displaying a JSON array in PHP (from freebase) 2010-12-24

    This is a very basic question, so excuse my lack of knowledge. I'm trying to output a JSON query from Freebase in PHP. I've already been able to parse the JSON into PHP using cURL and json_decode. Here is a link to the JSON array (for some reason I c

  • Send json post using php 2011-06-02

    I have this data: { userID: 'a7664093-502e-4d2b-bf30-25a2b26d6021', itemKind: 0, value: 1, description: 'Boa saudaÁ„o.', itemID: '03e76d0a-8bab-11e0-8250-000c29b481aa' } and I need to post into json url: http://onleague.stormrise.pt:8031/OnLeagueRest

  • Restlet 2.0.5 calling POST on Resource from browser 2011-06-15

    I have a Restlet 2.0.5 resource defined which includes a @POST annotation. I can interact successfully with this resource using a simple java application. I interact with this resource in my application utilizing restlet's PostMethodWebRequest(String

  • Json Post raw data from FLEX 2011-07-25

    I want to post raw data using FLEX and JSON (and get the result in PHP). I succeed to store my JSON data into an object and post object as HTTPService.send expects. But it isn't a post raw data. // my ActionScript code var objSend:Object = new Object

  • handling json data in php from jquery ajax 2011-11-12

    I created a json with this structure var data = { "people": [ { "name" : "John", "id" : 1 }, { "name" : "Marc", "id" : 2 } ] } Now here's how i send the data to the php var ordenDeCompra = JSON.stringify(data); $.post("../Backend/ordenesDeCompra.php"

  • PHP: How to receive JSON array from iPad app 2011-10-20

    Disclaimer: I am fairly new to using json. I am trying to use php to receive json data from an iPAd application. I know how to convert json to an array in php, but how do I actually receive it and store it into a variable so it can be decoded? Here a

  • How to receive and use a json in ajax sended from php? 2010-11-30

    I want to receive json from php to ajax and want to access the different field values in json. --------------Solutions------------- In jQuery it will be implementing something like this: var user = {}; $.ajax({ url: 'http://mysite.com/api/user.json',

  • iPhone- Send JSON Object to PHP server in POST and get response from server 2012-04-14

    Im trying to send JSON object to php server from my iphone The server will decode it do some functions and then replay with JSON back to iphone. I have the the server set up but im not sure what methods I need to use to connect to the php server (usi

  • Receive JSON object from HTTP Get in PHP 2012-04-18

    I am trying to implement a php client that sends an HTTP GET to the server which sends back a JSON object with the return information. I know how to decode the JSON once my php script has received it, but how would I go about actually getting it? EDI

  • Best way to pass JSON from Browser to PHP using Ajax.Request 2008-11-23

    Hi I have a JSON object that is a 2-dimentional array and I need to pass it to PHP using Ajax.Request (only way I know how). ...Right now I manually serialized my array using a js function...and get the data in this format: s[]=1&d[]=3&[]=4 e

  • How receive json object from client into a php 2D array at server? 2011-05-25

    I want to fill a 2D array in php from a JSON object in javascript at client. Can anybody help me to do this functionality? --------------Solutions------------- json_decode() http://php.net/manual/en/function.json-decode.php From the top of my head, w

  • How to write PHP to receive JSON from android 2011-07-03

    How to write PHP(server side) to receive JSON then insert to DB using android I write java to send data to PHP server : HttpPost httppost = new HttpPost("http://sit-edu4.sit.kmutt.ac.th/csc498/51270372/[My Folder].[My filename].php"); but I do not kn

  • Consuming JSON object in PHP, sent from jQuery 2009-11-19

    I'm sending a JSON object to PHP using jQuery via $.ajax({ url: myURL, type: 'POST', contentType: "application/json; charset=utf-8", data: myData, processData: false, dataType: 'html', async: false, success: function(html) { window.console.log(html);

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 1.834 (s). 14 q(s)