Re: AJAX form post
Arthur Ralfs <[email protected]> Sat, 11 Nov 2006 19:56:29 -0800
| Newsgroups | gmane.comp.mozilla.devel.xml |
|---|---|
| Message-ID | <[email protected]> |
Ben,
Unfortunately those few lines of code represent nearly all of my
knowledge about the
subject. It seems like a fairly arcane business. I don't think
anything I've tried has worked
the first time and that example took a distressing number of hours to
arrive at an
incantation that worked. Having said that as far as I know the
encodeURIComponent
function simply escapes some characters that would otherwise be
misinterpreted. I don't
remember anything about it being browser specific. I would be
surprised if it worked if
you omitted the 'x-www-form-urlencoded' line.
I guess you could pass more than one form element or maybe just assemble
everything into
one string and then disassemble it on the other end. The strings I am
sending have so far been
fairly short so I don't know about any character limit. I would just
give it a try before doing any
else.
Incidentally I didn't mean to respond privately, I didn't think to look
at the 'To:' field before hitting
send. I think the discussion could be potentially much more productive
if done in public. Maybe
somebody more knowledgeable will notice.
Arthur
Mueller Ben wrote:
> Arthur,
>
> Thanks for the response, but I'm still confused. First, is
> "encodeURIComponent" cross-browser/cross-platform? Also, what happens
> if you have to pass more than one form element? And is the
> x-www-form-urlencoded line required in this setting? It would appear
> that you're taking form data and converting it to a URL, then passing
> that data along, but the URL scope has a character limit, so what
> happens if you try to pass along a lot of data?
>
>
> On Nov 11, 2006, at Saturday11/11/06, Arthur Ralfs wrote:
>
>> hairbo wrote:
>>> Apologies if this is the wrong forum for this question.
>>>
>>> I have some AJAX code that currently just uses a "GET" method, like
>>> this:
>>>
>>> if (IE)
>>> req = new ActiveXObject("Microsoft.XMPHTTP");
>>> else
>>> req = new XMLHttpRequest();
>>>
>>> req.open("GET", url, true);
>>> req.send();
>>>
>>> ...where "url" is the url with querystring params.
>>>
>>> This works fine if I don't have to send all that much data along, but
>>> I'd like to expand my code so that I can pass large blocks of data via
>>> my AJAX code.
>>>
>>> I've done a little digging online, but all I've found so far suggests
>>> that doing FORM posts via XmlHttpRequest is just hideously ugly--you
>>> have to loop over all elements on the page, then build out a key/value
>>> string (just like a querystring), and then pass that as part of the
>>> "send()" function. All of the code I saw made it look just godawful.
>>> Are there any good tutorials out there for this sort of thing? Is it
>>> really godawful to work with XmlHttpRequest and form posts?
>>>
>>> Thanks in advance,
>>> Ben Mueller
>>>
>>> _______________________________________________
>>> dev-tech-xml mailing list
>>> [email protected]
>>> https://lists.mozilla.org/listinfo/dev-tech-xml
>>>
>>>
>>>
>>>
>> Hi Ben,
>>
>> This is what I use for my Firefox extension. I'm not interested in IE
>> so I don't bother testing for it.
>> Maybe what you're doing is more complicated however. The 'axcom0'
>> element is a text entry
>> box.
>>
>> Arthur Ralfs
>>
>> function makeRequest() {
>> http_request = new XMLHttpRequest();
>> var command = document.getElementById('axcom0').value;
>> http_request.open('POST', 'http://127.0.0.1/axiom/axiom.php', true);
>> http_request.onreadystatechange = handleResponse;
>> http_request.setRequestHeader('Content-Type',
>> 'application/x-www-form-urlencoded');
>> http_request.send("command="+encodeURIComponent(command));
>> }
>>
>>
>>
>
>
>
>