note 72489 added to function.json-decode

From: Date: Sun, 21 Jan 2007 03:08:03 +0000
Subject: note 72489 added to function.json-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-121973@lists.php.net to get a copy of this message
I've written a javascript function to get around this functions limitations and the limitations imposed by IE's lack of native support for json serialization. Rather than converting variables to a json formatted string to transfer them to the server this function converts any javascript variable to a string serialized for use as POST or GET data. String js2php(Mixed); js2php({foo:true, bar:false, baz: {a:1, b:2, c:[1, 2, 3]}})); will return: foo=true&bar=false&baz[a]=1&baz[b]=2&baz[c][0]=1&...etc function js2php(obj,path,new_path) { if (typeof(path) == 'undefined') var path=[]; if (typeof(new_path) != 'undefined') path.push(new_path); var post_str = []; if (typeof(obj) == 'array' || typeof(obj) == 'object') { for (var n in obj) { post_str.push(js2php(obj[n],path,n)); } } else if (typeof(obj) != 'function') { var base = path.shift(); post_str.push(base + (path.length > 0 ? '[' + path.join('][') + ']' : '') + '=' + encodeURI(obj)); path.unshift(base); } path.pop(); return post_str.join('&'); } ---- Server IP: 216.194.113.175 Probable Submitter: 71.193.154.92 ---- Manual Page -- http://www.php.net/manual/en/function.json-decode.php Edit -- https://master.php.net/note/edit/72489 Del: integrated -- https://master.php.net/note/delete/72489/integrated Del: useless -- https://master.php.net/note/delete/72489/useless Del: bad code -- https://master.php.net/note/delete/72489/bad+code Del: spam -- https://master.php.net/note/delete/72489/spam Del: non-english -- https://master.php.net/note/delete/72489/non-english Del: in docs -- https://master.php.net/note/delete/72489/in+docs Del: other reasons-- https://master.php.net/note/delete/72489 Reject -- https://master.php.net/note/reject/72489 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#121973) next »