The first thing I noticed was that your onclick
handler  attribute doesn't "return false;" after
executing your Ajax method; perhaps it's doing both
the Ajax submit and a regular one (easily verifiable)?

It might be less traumatic to just figure out what's
wrong with the built-in Ajax, though :/

d.

--- 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