jquery - How can I avoid that a Spring controller method return a logical view name and return a String value used to handle and AJAX request? -


i pretty new in spring mvc , ajax , have following doubt.

using jquery performing ajax request:

$.ajax({     type : "get",     url : "salvaappuntiministeriale",      data: {          'codiceprogetto': codiceprogetto,         'appuntiministeriale': appuntiministeriale           }      }).done(function(response) {         showsuccessmessage('nota inserita');         document.open();         document.write(response);         document.close();      }).error(function(xhr) {         manageerror(xhr); });  

as can see, perform request toward salvaappuntiministeriale resource passing 2 values (that retrieved page, works fine).

then, spring mvc controller class, have controller method handle previous ajax request:

@requestmapping(value = "salvaappuntiministeriale", method=requestmethod.get) public string salvaappuntiministeriale(@requestparam string codiceprogetto, @requestparam string appuntiministeriale, model model) throws exception {      system.out.println("codice progetto: " + codiceprogetto + " nota ministeriale: " + appuntiministeriale);      twp1007progetto progetto = progettoservice.getprogetto(integer.parseint(codiceprogetto));      progetto.setdesnotapp(appuntiministeriale);      progetto.setcodpgmultmov("inserimento nota minitseriale");              // codice azione ultima modifica     progetto.setcoduteultmov(this.getutenteconnesso().getusername());       // utente ministeriale che ha variato l'anticipo     progetto.setdatoraultmov(new date());                                   // data ed ora della variazione dell'anticipo      progettoservice.salvanotaappunto(progetto);      model.addattribute("progetto", progetto);      return "visualizzaprospetto/prospettorendicontazione"; } 

this works fine. correctly handle previous request , return logical name of entire view entirely reloaded in current tab these lines previous jquery code:

document.open(); document.write(response); document.close(); 

this works fine not want change behavior , want avoid entire page returned , reloaded.

so need following operations:

  1. i don't want previous salvaappuntiministeriale() controller method return logical view name (because have not reload page).

  2. the salvaappuntiministeriale() method have return value of **appuntiministeriale progetto object (i have retrieve sure value correctly saved in db, not important now). maybe have put responsebody?

  3. into callback function called done() of jquery done have retrieve previous value can update content of html field page.

so, how can implement behavior? how can avoid return logical view name , return string value , retrieve .done() function?

just return object want pass front-end , annotate controller @restcontroller annotation, or controller method @responsebody.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -