You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Li Ying <li...@gmail.com> on 2010/12/01 01:10:27 UTC

Re: Calling Struts Action from JavaScript

Chris is right.

On the client side, there is not such a concept of "Struts
Action".There is Server Side Resource only.

You have to access(post or get) it by URL, param, and you must handle
the response from the server side.


Code should looks like:

(1)Client side JavaScript
Send a request to Server side. (Post or Get)

(2)Server side do the validation first.
When the param data is not good. Do nothing, and send a "FAIL
FLAG"+"ErrorMessage" as response.

(3)When the validation passed, insert data into DB,
and send a "OK FLAG" as response.

(4)Client Side JavaScript receive the response.
If it is a "FAIL", show error on the page.
If it is a "OK", append data to the table.

About the response, You can use plain text, HTML, XML, or JSON.
I recommend JSON, because it is very friendly to client side JavaScript

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org