[英]How to send JSON object from spring controller to javascript?
I need to send JSON object from spring controller to javascript and recieve it with ajax. 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?
有没有人知道怎么做?
There are various ways you can call Spring
rest service from javascript
.您可以通过多种方式从
javascript
调用Spring
rest 服务。 You can choose pure javascript
usingXMLHttpRequest , jQuery Ajax , Fetch etc. It really depends on you requirements.您可以选择纯
javascript
使用XMLHttpRequest , jQuery Ajax 等,这真的取决于你的要求。 You can look at individual link for more details.您可以查看单个链接以获取更多详细信息。 Here is one simple example using
jQuery Ajax
.这是一个使用
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
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.