AJAX for feedback Mar07 '06

I’ve recently implemented an AJAX approach for leaving feedback, at this site (for no other reason than getting practice with using AJAX). When you leave feedback, the page will still reload, but it’s all done through JavaScript, now.

I am glad I got this to work, because I was initially struggling to figure out how to "POST" data via the xmlHttpRequest() object.

It turns out it’s almost identical to using the "GET" approach, except you specify the Request Header:

xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");

I’m not even sure this is the "right" way to specify this, but it seems to work great.

Another tricky part to using "POST" is that you still have to submit a query string, with matching name/value pairs, much like the "GET" approach in the URL:

var queryString = "name=" + name + "&email=" + email;

So... even if you are "posting" a giant textarea (such as feedback), it still gets "appended" to the query string.

Anyway, hopefully it works OK. I think I’ve worked through all the kinks.

You can see the JavaScript here.

Categories: JavaScript , Web Development

Add Feedback (view all)

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

matthom is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Contact Matt

Similar Entries

Stats

3 unique visits since November 2008

Syndicate

Advertisements