Send JSon data from javascript to php -



Send JSon data from javascript to php -

i'm trying post array in javascript php session variable using json. searched lot, there 3 ways post; html form posting request, ajax , cookies. want post posting request, in script convert array json object no problem. tried send php page this;

$('#firstconfirmbutton').click(function(){ var json_text = json.stringify(ordersarray, null); alert(json_text.tostring()); request= new xmlhttprequestobject(); request.open("post", "test.php", true); request.setrequestheader("content-type", "application/json"); request.send(json_text); });

in test.php tried array using file_get_contents('php://input') did not work. when seek echo son_text, shows "firstconfirmbutton=" instead of array content. should do?

<?php require("includes/db.php"); require("includes/functions.php"); session_start(); if (isset($_post['firstconfirmbutton'])) { $json_text = \file_get_contents('php://input'); echo $json_text; }

?>

apul right using ajax library. on php side, 'receive' info using

$value = urldecode(file_get_contents('php://input'));

javascript php ajax json

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -