Forum Moderators: open

Message Too Old, No Replies

sending AJAX data via POST via javascript?

         

defireman

10:25 am on Dec 25, 2005 (gmt 0)

10+ Year Member



I'm currently using javascript to collect up formdata, and wish to use javascript to trigger an AJAX request. Is there a way to send AJAX data via post?

(BTW, I am using the RICO AJAX framework. I appreciate any help in this area.)

Bernard Marx

10:15 pm on Dec 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I thought the idea of AJAX is that you don't have to post info using forms, and cause a page reload.

If you want to pass an XML string with a form, just use it as a value for an
<input type="hidden">.

defireman

4:31 am on Dec 26, 2005 (gmt 0)

10+ Year Member



what I mean is that I want to send POSTDATA with an AJAX request, which means that I will need to use JS or something to POST the data with the request. Is there a way to do that?

Rambo Tribble

3:01 pm on Dec 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are a number of tutorials on the web demonstrating the POST method with XMLHttpRequest. Here's one: [designplanet.biz...]

Bernard Marx

3:42 pm on Dec 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This was an interesting one. The tutorials I found, suggested (as expected) simply sending the POST data:..

xmlhttp.send('var0=yes&var2=no');

Yet this didn't work (I've been testing with PHP server-side, as no access to ASP today).

POST data isn't usually such a string, so I had a look around for ideas as to how to set the enctype (or whatever), and found success with the

setRequestHeader
method.

xmlhttp.open( "POST", url, false );
xmlhttp.setRequestHeader(
'Content-Type',
'application/x-www-form-urlencoded; charset=UTF-8'
);
xmlhttp.send("apples=yes&bananas=no")

Tested in IE6 & FF1

How does one deal with binaries, image uploads for eg, I wonder?

Bernard Marx

3:46 pm on Dec 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Meanwhile, if I had just waited for Tribble to post that
DesignPlanet URL
[designplanet.biz], I could have saved myself a lot of bother. It's all there. Nice.

execute

8:34 pm on Dec 26, 2005 (gmt 0)

10+ Year Member



There are also rumors that there will be Hidden-iframe tutorials, and XML tutorials with AJAX in designplanet forums. Oh wait, that's because i'm writing them :> (just sorting some bugs).

You guys can write your tutorials too on designplanet.biz just have to register.