Every ajax request gets an error. Ajax Function:
function doAjax() {
var inputText = $("#info").val();
$.ajax({
type: 'POST',
url: 'ajax',
dataType: 'json',
data: 'text='+inputText,
success: function (response) {
$("#result_info").text(response);
}
error: function (e) {
alert('error' + e.responseText);
}
});
}
Java controller
@RequestMapping(value = {"/ajax"}, method = RequestMethod.POST)
public @ResponseBody String showText(@RequestParam String text) {
System.out.println(text);
String returnText = "empty";
if (!text.isEmpty()) {
returnText = " response: " + text;
}
return returnText;
}
Besides this question you could tell what is the difference between in ajax request
data: ({text: inputText}),
data: 'text='+inputText,
source
share