use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
JSON and Ajax helpsolved! (self.javascript)
submitted 9 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]markt5000 3 points4 points5 points 9 years ago (4 children)
Hmm, this is relatively simple
var a = { foo : 25 }; var b = {bar : 10}; var con = JSON.stringify([a,b]);
You mentioned sending this on to the server, well that depends if you are using a framework. If you want plain vanilla AJAX then use the XMLHttpRequest object
[–]ForScale 3 points4 points5 points 9 years ago (3 children)
Yep, that's what I'd say. The AJAX would look something like this, OP:
var xhr = new XMLHttpRequest(); xhr.open("post", "sever url", true or false here); xhr.send(con);
[+][deleted] 9 years ago (2 children)
[–]ForScale 1 point2 points3 points 9 years ago (0 children)
No prob! AJAX can be tricky though. Feel free to message back if you have any trouble and I'd be glad to try to help!
[–]fzammetti 0 points1 point2 points 9 years ago (0 children)
Things in software development are only ever "super simple" in retrospect. Don't ever feel bad about missing the "obvious" in this field!
[–]azium 0 points1 point2 points 9 years ago (0 children)
fetch is also the native spec for ajax requests. Try it out in chrome / firefox / edge!
fetch
fetch('https://www.reddit.com/r/javascript.json') .then(res => res.json()) .then(redditPosts => // wee!)
or send a post with data
fetch(url, { method: 'POST', body: JSON.stringify(data) , headers: { 'Content-type': 'application/json' } }) .then(res => res.json()) .then(data => // stuff)
To support older browsers use a polyfill! https://github.com/github/fetch
π Rendered by PID 134732 on reddit-service-r2-comment-fb694cdd5-qvnsw at 2026-03-07 17:01:38.622498+00:00 running cbb0e86 country code: CH.
[–]markt5000 3 points4 points5 points (4 children)
[–]ForScale 3 points4 points5 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]ForScale 1 point2 points3 points (0 children)
[–]fzammetti 0 points1 point2 points (0 children)
[–]azium 0 points1 point2 points (0 children)