AJAX can send post data?
Printable View
AJAX can send post data?
Yep.
After the open() call, rather than send(null) or send(''), you should send("name1=value1"); send("name2=value2"); and so on, for as many name/value pairs as you like.
Is there any way to attach that to a link?
(I suppose you could add an onClick attribute)
I don't know if it was your intent, but that reads like a suggestion to call the send method twice or more for a single request.Quote:
Originally Posted by Twey
To send data in a POST request, one has the option of either composing a query string-like set of data where name/value pairs are combined with an equals symbols (=), and pairs are separated by an ampersand (&). Alternatively, the entity body should be a well-formed MIME message body. In either case, both a Content-Type and Content-Length header should be included in the request headers unless there is very good reason not to include them (and there should never be, in this instance).
The HTML specification defines the unregistered media type, application/x-www-form-urlencoded for use when taking the first option, though other values are also known (and quite similar).
Why on Earth bother? Just use a form and be done with it. If you really want the button to look like a link, style it as such.Quote:
Originally Posted by djr33
Links are for navigation, forms are for user input. Use them both properly. Don't arse around with AJAX when something far more reliable and simple is available instead.
Mike
POST data being sent by a form can be limited, so it's nice to have a couple ways around it.
I think the best idea is to use a form with a button styled as a link.... good idea.
Anyway.... I'm just curious, more than really needing a solution.