Я уже задавал подобный вопрос несколько дней назад, но теперь у меня есть проблема. Я не могу вернуть значения, которые я хочу, в контроллер. Допустим, у меня есть этот контроллер
@RequestMapping(value = "/ricercaUtente", method = {RequestMethod.POST,RequestMethod.PUT}, consumes = {MediaType.APPLICATION_JSON_VALUE}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<BaseAjaxResponse<List<UtenteDto>>> ricercaUtente( @RequestParam (required=false) String nome, @RequestParam (required=false) String cognome){
return List;}
Это мой html ..
<form id="myForm" action="/rest/ricercaUtente">
<input type="text" id="nome" name="nome">
<input type="text" id="cognome" name="cognome">
<input type="submit" id="submit" name="submit">
</form>
, и это мой ajax
$(function() {
console.log( "DOM pagina di esempio caricato" );
$("#myForm").submit( function(evt){
//Stoppo il comportamento di default del submit
evt.preventDefault();
ricercaUtente();
} );
});
function ricercaUtente(){
var ricarcaUtenteUrl = $("#ricercaUtenteUrl").val();
nome = $("#nome").val();
cognome = $("#cognome").val();
$.ajax({
url : ricarcaUtenteUrl,
dataType : 'json',
contentType : 'application/json; charset=UTF-8',
type : 'POST',
data: JSON.stringify({nome:nome,cognome:cognome}),//tried this and {nome: nome, cognome: cognome}
beforeSend : function(){
var busyImgUrl = $("#busyImgUrl").val();
$.blockUI({ message: '<h1><img src="'+busyImgUrl+'" /></h1>' });
},
complete : function(){
$.unblockUI();
},
success : function(data) {
var codiceEsito = data.operationResultCode;
var datiContatto = new Object();
if (codiceEsito == 200) {
datiContatto.utente = data.payload;
} else{
datiContatto.errore=true;
}
},
error : function(data) {
var datiContatto = new Object();
datiContatto.errore=true;
}
});}
Я попытался запустить tomcat в режиме отладки, но значения "nome" и "cognome "всегда нулевые ... Кто-нибудь знает, что я делаю не так?