Issue
I need to send JSON object from spring controller to javascript and recieve it with ajax. Is there someone who knows how to do it?
Solution
There are various ways you can call Spring
rest service from javascript
. You can choose pure javascript
using XMLHttpRequest , jQuery Ajax , Fetch etc. It really depends on you requirements. You can look at individual link for more details. Here is one simple example using jQuery Ajax
.
var jqxhr = $.ajax({
url:"/your-url"
type:"GET",
data:inputData,
dataType: "json"
});
//Handle a successful call to data service
jqxhr.done(function( data, textStatus, jqxhr) {
// your code for success
});
//Handle an unsuccessful call to data service
jqxhr.fail(function(jqXHR, textStatus) {
// your code to handle fail
});
jqxhr.always(function () {
//your code
});
});
Answered By - want2learn