I really recommend using something like Prototype to do your Ajax
stuff.  There's no need to reinvent the wheel and introduce countless
bugs in the process, Prototype is tested for all relevant browsers and
it'll take you 10 minutes to do what you're trying to do if you use
it:

http://www.prototypejs.org/api/ajax/request
http://www.prototypejs.org/api/ajax/options

Good luck,
Zarar

On 9/27/07, Henry Park <[EMAIL PROTECTED]> wrote:
>
>
> I could not get the packaged struts2 ajax implementation to work, so I am 
> trying to go at it with plain javascript. A problem that I am having is that 
> whenever I submit the form, all of my form fields keep getting appended over 
> and over. If I click submit enough, it causes an overflow error. Can you take 
> a look at my code? Thanks.
>
> <script language='Javascript'>
> function retrieveURL(url, target, submitFormFlag, nameOfFormToPost) {
>   var req = getXmlHttpRequest();
>   var method = "GET";
>   if (submitFormFlag) {
>     url = url + getFormAsString(nameOfFormToPost);
>     method = "POST";
>
>
>       req.setRequestHeader("Content-Type", 
> "application/x-www-form-urlencoded");
>    }
>
>
>   req.onreadystatechange = function() {
>   if (req.readyState == 4) {
>     if (req.status == 200) {
>       if (req.responseText.length > 0) {
>         target.innerHTML = "";
>         target.innerHTML = req.responseText;
>       }
>     } else {
>       alert("Error encountered. Please contact support.");
>     }
>   }
>   req.open(method, url, true);
>   req.send(null);
>   return false;
> }
>
> function getFormAsString(formName){
>   var x = document[formName];
>   returnString = "?1=1";
>   formElements = document[formName].elements;
>   for(var i = formElements.length-1; i >= 0; --i) {
>     returnString = returnString + "&" + encodeURI(formElements[i].name) + "=" 
> + encodeURI(formElements[i].value);
>   }
>   return returnString;
> }
>
> function do_submit() {
>   retrieveURL('NameOfAction!list.action', sometarget, true, 'aform');
> }
> </script>
>
> <form name='aform'>
>   <s:textfield name="field1" value="%{field1}" />
>   <s:textfield name="field2" value="%{field2}" />
>   <s:textfield name="field3" value="%{field3}" />
>   <s:textfield name="field4" value="%{field4}" />
>   <s:textfield name="field5" value="%{field5}" />
>   <input type='button' value='submit' onclick='do_submit()'/>
> </form>
>
> <div id='sometarget'></div>
>
>
> _________________________________________________________________
> Connect to the next generation of MSN Messenger
> http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to