AJAX form post

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

AJAX form post

hairbo
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
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: AJAX form post

Alex Vincent
hairbo wrote:
> 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?

Yes, it's really awful.  :)

I wrote a serverpost widget for XUL some years back; you can find it
through http://xulwidgets.mozdev.org/ .

Alex Vincent
Santa Cruz, CA, USA
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: AJAX form post

Arthur Ralfs
In reply to this post by hairbo
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
>>> [hidden email]
>>> 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));
>> }
>>
>>
>>
>
>
>
>


_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: AJAX form post

hairbo
In reply to this post by Alex Vincent
Alex,

Thanks for the reply.  I just now saw it.  I searched the URL you
provided, and couldn't find the widget you referred to.

I'm disappointed to hear that posting data via XmlHttpRequest is so
ugly, and I'm surprised as well.  It sure looks like lots of websites
out there are throwing around large quantities of data via
XmlHttpRequest form posts (gmail, etc), so it seems odd that it would
be so unpleasant to use.

It also sounds like you wrote something that works with Mozilla only.
Is that correct?  I'm hoping to find a cross-browser solution, or at
least good clues on how to develop a cross-browser solution.

Thanks,
Ben Mueller

Alex Vincent wrote:

> hairbo wrote:
> > 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?
>
> Yes, it's really awful.  :)
>
> I wrote a serverpost widget for XUL some years back; you can find it
> through http://xulwidgets.mozdev.org/ .
>
> Alex Vincent
> Santa Cruz, CA, USA

_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: AJAX form post

Dylan Schiemann-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This is where toolkits like Dojo make life easier.

- -Dylan

hairbo wrote:

> Alex,
>
> Thanks for the reply.  I just now saw it.  I searched the URL you
> provided, and couldn't find the widget you referred to.
>
> I'm disappointed to hear that posting data via XmlHttpRequest is so
> ugly, and I'm surprised as well.  It sure looks like lots of websites
> out there are throwing around large quantities of data via
> XmlHttpRequest form posts (gmail, etc), so it seems odd that it would
> be so unpleasant to use.
>
> It also sounds like you wrote something that works with Mozilla only.
> Is that correct?  I'm hoping to find a cross-browser solution, or at
> least good clues on how to develop a cross-browser solution.
>
> Thanks,
> Ben Mueller
>
> Alex Vincent wrote:
>> hairbo wrote:
>>> 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?
>> Yes, it's really awful.  :)
>>
>> I wrote a serverpost widget for XUL some years back; you can find it
>> through http://xulwidgets.mozdev.org/ .
>>
>> Alex Vincent
>> Santa Cruz, CA, USA
>
> _______________________________________________
> dev-tech-xml mailing list
> [hidden email]
> https://lists.mozilla.org/listinfo/dev-tech-xml
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFYgY/8nLgh/JJsxERAuIDAKCA5T5QgkPR/B76SZFFUfVZ4jhPoQCfUzv2
UcDpe6+C98WryVOWaAdhfV4=
=kisw
-----END PGP SIGNATURE-----
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: AJAX form post

Alex Vincent
In reply to this post by hairbo
hairbo wrote:
> Alex,
>
> Thanks for the reply.  I just now saw it.  I searched the URL you
> provided, and couldn't find the widget you referred to.

Sorry, you have to install the XUL Widgets xpi to use it.  Reference
http://xulwidgets.mozdev.org/testcases/ for some testcases after you've
installed XUL Widgets, or chrome://xulwidgets/content/tests/tests.html
within the browser.

  > It also sounds like you wrote something that works with Mozilla only.
> Is that correct?  I'm hoping to find a cross-browser solution, or at
> least good clues on how to develop a cross-browser solution.

Yeah, it's Mozilla-only.

Alex
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

RE: AJAX form post

Klotz, Leigh
In reply to this post by Dylan Schiemann-2
You might want to take a look at XForms, which is a W3C markup-based way
of doing XML submissions.
There is an 0.8 version of an XPI for it for Firefox and Mozilla.  There
are also plug-ins for IE, and server-side tools for doing
transformations to make it work (using Dojo and DWR and other AJAX
libraries) in all browsers.
Leigh.

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Dylan
Schiemann
Sent: Monday, November 20, 2006 11:47 AM
To: hairbo
Cc: [hidden email]
Subject: Re: AJAX form post

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This is where toolkits like Dojo make life easier.

- -Dylan

hairbo wrote:

> Alex,
>
> Thanks for the reply.  I just now saw it.  I searched the URL you
> provided, and couldn't find the widget you referred to.
>
> I'm disappointed to hear that posting data via XmlHttpRequest is so
> ugly, and I'm surprised as well.  It sure looks like lots of websites
> out there are throwing around large quantities of data via
> XmlHttpRequest form posts (gmail, etc), so it seems odd that it would
> be so unpleasant to use.
>
> It also sounds like you wrote something that works with Mozilla only.
> Is that correct?  I'm hoping to find a cross-browser solution, or at
> least good clues on how to develop a cross-browser solution.
>
> Thanks,
> Ben Mueller
>
> Alex Vincent wrote:
>> hairbo wrote:
>>> 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?
>> Yes, it's really awful.  :)
>>
>> I wrote a serverpost widget for XUL some years back; you can find it
>> through http://xulwidgets.mozdev.org/ .
>>
>> Alex Vincent
>> Santa Cruz, CA, USA
>
> _______________________________________________
> dev-tech-xml mailing list
> [hidden email]
> https://lists.mozilla.org/listinfo/dev-tech-xml
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFYgY/8nLgh/JJsxERAuIDAKCA5T5QgkPR/B76SZFFUfVZ4jhPoQCfUzv2
UcDpe6+C98WryVOWaAdhfV4=
=kisw
-----END PGP SIGNATURE-----
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml