/    Sign up×
Community /Pin to ProfileBookmark

Fetching JSON data to server

I am having trouble sending JSON data to a server.
Its definitely reaching the parser.php, but I am not what to create in PHP to fetch this data. Also I am not sure my Javascript is correct.

<SCRIPT>
var JSONObject = new Object;
JSONObject.description = “hello”;
JSONstring = JSON.stringify(JSONObject);
runAjax(JSONstring);

var request;
function runAjax(JSONstring)
{
// function returns “AJAX” object, depending on web browser
// this is not native JS function!
var request;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
request=new XMLHttpRequest();
}
else
{// code for IE6, IE5
request=new ActiveXObject(“Microsoft.XMLHTTP”);
}
request.open(“POST”, “http://www.somedomain.com/parser.php“, true);
request.setRequestHeader(“Content-type”,”application/x-www-form-urlencoded”);
request.send(JSONstring);
}

</SCRIPT>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 18.2011 — <i>
</i>var JSONObject ={};
Copy linkTweet thisAlerts:
@CX_ASEauthorApr 18.2011 — Great, I was not too far off on the client side.

How do I capture the JSON data on the server side?
Copy linkTweet thisAlerts:
@KorApr 18.2011 — It depends on the server-side language you are using. If PHP, you should use the $_POST variable and:

http://www.php.net/manual/en/function.json-decode.php
Copy linkTweet thisAlerts:
@CX_ASEauthorApr 18.2011 — The JSON data I am transmitting is quite large, I dumped the data on the server side, and I noticed the data got cut off. I must of hit some limit.
Copy linkTweet thisAlerts:
@KorApr 19.2011 — No, there is no limit. If data is truncated, that means some illegal character must have been used. Have you used UTF-8 char map in your document? JSON serialization/parsing need utf-8 character encoding
×

Success!

Help @CX_ASE spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...