Refresh div by a AJAX + jQuery + Spring MVC request - ajax

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.

Related

Trigger custom JSP tag manually

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!

Prevent page reloading in Struts 2

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.

Spring with AJAX integration

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.

How to call action of struts2 from open method of ajax xmlhttp.open("GET", "action_name", true);

I want to get some data from action of struts2 and assign it to the object created in jsp file by using ajax
Give it the URL to your Struts2 action. If you need to return JSON from your action, there is a plugin for that which comes bundled with Struts2.
Calling a struts action is very easy just mention the action name as the url.In order to get some data from action and use it in your jsp take a look at this link

Telerik MVC: Loading Grid with ajax request don't work

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

Resources