When we want to handle a Ajax request in ATG
Step-by-step guide
On the form handler.
- Create a new handle method.
- Write the required logic inside the method
- Don't use checkFormRedirect(); create a json object instead and write it to the response.
JSONObject responseJson = new JSONObject();
responseJson.put("ShoppingCartItemCount", getOrder().getCommerceItemCount());pResponse.setContentType(APPLICATION_JSON);
PrintWriter out = pResponse.getWriter();
out.print(responseJson.toString());
out.flush(); - The handle method should return 'false'.
On the jsp/javascript
- Create a usual dsp form with the submit method pointing to our handle method declared in form handler.
- Use javascript to do a ajax submit of the form.
- The response will be coming as json. Handle the response in javascript.
No comments:
Post a Comment