开发者

HTML <body onload=""> doesn't stop

开发者 https://www.devze.com 2023-02-04 22:21 出处:网络
I\'ve got the following 开发者_如何学Python <body onload=\"document.myform.submit()\"> and it doesnt stop submitting the form. I think everytime it submits the form the page loads again and i

I've got the following

开发者_如何学Python
<body onload="document.myform.submit()">

and it doesnt stop submitting the form. I think everytime it submits the form the page loads again and it submits it again and so on. how do i stop it?

edit: my form is an empty form im submiting it just to involke my action class into putting data in request and then redirecting back to my jsp page again for the page to display it, so i want it to submit as soon as the page loads.


Yeah, you've created an infinite loop.

How to stop it? Remove it from onload on the body.

Not sure exactly what you're trying to accomplish here though.

* Update (in response to your update) *

I'd recommend using AJAX to post in this case.

Take a look at jQuery:

http://api.jquery.com/jQuery.ajax/


When you submit the form, the browser navigates to whatever page the server sends back.
If that page submits the form again, you'll get an infinite loop.


Yes, I think your explanation of the cause is correct.

It's easy to fix: Just remove your onload attribute. It makes absolutely no sense.


Whats in the rest of the HTML ? specifically the <form> tag ?


If the form on your page is posting to the page it is on, then yes, it will non stop submit.

What are you trying to achieve exactly? Probably best to remove the onload line, or change the action of the form element to an alternative location.

HTML <body onload=""> doesn't stop

Edit

As per your edit, consider an AJAX request on a timer. This would be much less obtrusive to the user.

0

精彩评论

暂无评论...
验证码 换一张
取 消