/    Sign up×
Community /Pin to ProfileBookmark

dynamically append form data to a post request

I am analyzing header tags for submitting forms online in order to better understand how htmlhttp forms work- signing in to gmail, yahoo mail, and amazon, using the network tab of google developer tools, to view the http headers of requests and responses, and learn where they come from. I am seeing very peculiar behavior in my browser’s (chrome)request headers when signing into amazon. The form data, always has the following two header names appended to the second and third to last places of the form data query: x=(some random number), and y=(some random number).

There are no input tags getting dynamically generated, since when i tell google chrome to break on all subtree modifications, the site still sends off the post with the added parameters before anything gets modified, BEFORE crashing.

There also is NO ajax call which is causing dynamically added data to be appended to the form post.

My question is this: is there any way, using javascript, to instruct a browser, to append data as data, to a form post, WITHOUT the use of dynamically appended input elements, or ajax?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@toicontienDec 11.2011 — There is no way to provide pure binary data in the POST, however with the combination of JSON and a server side script able to parse JSON into a hash array, you can fake it using a hidden form field.

First, go to http://www.json.org/ and download json2.js, this provides the ability for JavaScript to safely encode and decode a JSON string and guards against cross site scripting attacks. Now you can pass arbitrarily deep data structures to the backend:

[B]JavaScript/HTML[/B]
[CODE]<script>
var data = {
title: "Jobs",
names: ["John", "Bill", "Stacey"],
positions: [
{title: "Engineer", id: 1},
{title: "Manager", id: 2}
]
};

document.getElementById("my_form").onclick = function() {
[B]this.elements.json.value = JSON.stringify(data);[/B]
};
</script>

<form id="my_form">
... visible form fields
[B]<input type="hidden" name="json">[/B]
</form>[/CODE]


And on the server side:

[B]PHP[/B]
[CODE]$data = json_decode($_POST['json']);
echo $data['title'];
echo $data['names'][1];
echo $data['positions'][0]['title'];[/CODE]
×

Success!

Help @jmu2101 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.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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