Lets pretend that we have custom JSP tag somewhere on page:
<myTag:loadList data=${asyncData} />
When a page starts loading, asynchronous AJAX call to server is made. As a result of this call the data for asyncData parameter should be provided.
The question is - how can I "trigger" my custom tag for rendering manually based on successful AJAX request? Thank you!
Related
I am currently working on a small web app and this is the first time i am using Struts2. Here is what i am trying to achieve.
A Struts2 JSP page on form post, calls a struts action. Once this action completes it task, I need to return to the calling JSP with out any page reloading (avoid postback).
how can i achieve.can any one please help me?.
It is called AJAX (no kidding).
In Struts2 you can use Struts2-jQuery Plugin to achieve that pretty easily.
As AndreaLigios said, you can achieve this using struts-j query plug-in.
Create a remote page to display your result.
use
<sj:sbmit targets="[div_id]" />
on your main page to submit the form
Add a div to your main page to display the remote page.
<div id="[div_id]" />
In your struts.xml, just return the remote page as a result of your action.
So I'm able to successfully integrate AJAX requests with Spring MVC. However, I have a problem- if I click the "submit" button of my form, my #Controller class detects the url and returns a ModelAndView. However, what I want is that there be an AJAX check first, and if the form submission is not successful (e.g., blank fields), return an AJAX response. Otherwise, proceed as per normal and display a ModelAndView. However, I have no clue how to integrate both at the same time.
Any ideas or tutorials are appreciated.
Thanks!
You have several choices:
submit the form to a specific, different URL, when using AJAX
add a specific parameter to the request when posting using AJAX, and use this specific parameter to check if the request is n AJAX request
test if the X-Requested-With request header is present and contains XMLHttpRequest
I would go the PJAX route or what's also known as HiJax.
Basically you return a subset of the page if it's an AJAX request using headers. Most people than just use conditions in their view/template to decide to include the full or chrome-less HTML.
I dont know how to resolve this. I am using Spring MVC to resolve the views but I don't want to redirect to a new page, I just want to load the response in a div.
Let me explain it a bit. First I want to make an AJAX request to the Spring MVC controller that resolves the view, but I want to load that view in a div. I don't know if it's possible...
Thanks in advance
Use jQuery's .load( ) method:
http://api.jquery.com/load/
Call a regular handler method from jQuery ($.get), and replace the <div> html contents with the HTML coming back from the handler call.
i have a form that it send data with ajax post metod. when i set flashmessenger in action method, it don`t show any messege (i have to refresh the page for see the messege)!
how i can manage the flashmessenger for recognition ajax load page??
Flashmessenger uses sessions, in order for it to work you need to physically reload the page. You have to create your own mechanism; Whenever you get the callback you can append lets say your response to the same element in which you would have displayed the flashmessanger message.
I have a Telerik MVC Tabstrip.
I have used:
.LoadContentFrom("Grid", "Orders");
"Grid" Action just returns view without model. Then the Ajax request should have been fired to get the data.
It is loading the grid normally but it is not calling the Ajax request to fill the data.
If I am calling the same action normally i.e. without ajax it displays grid and fires Ajax request to load the data.
Perhaps you've missed to register the required JavaScript files for the Grid. You can check the following help topics:
Loading components in tab content
Required JavaScript files
Check the sample available at here.
This one uses MVC 1.0 but can be surely converted to MVC 2.0