jsp - Get Action class result (return) String in JQuery ajax success -


in jsp page, have form , divs

<form id="persondetail" name="persondetail" action="persondetail"> <!-- input fields --> </form> <div id="sucess"></div> <div id="error"></div> <div id="edit"></div> <div id="input"></div> 

i using ajax call submit form.

in action class have following code

actionclas

if(condition1) { //processing statements return "success"; } else if(condition2) { //processing statements return "error"; } else if(condition3) { //processing statements return "input"; } else if(condition4) { //processing statements return "edit"; } 

ajax call

$(document).on('click', ".savebutton", function(){         var formid='persondetail';         var form = $("#"+formid);         form.submit(function ()         {                 var urlaction=form.attr('action');                 var datafields=form.serialize();                 $.ajax({             type: "post",             url: urlaction,             data: datafields,             success: function (data) {                     var ajaxresult= $('<div/>').html(data),                     $ajaxcontent = ajaxresult.find('#ajaxcontent');                 var ajaxactionresult=$('<div/>').html($ajaxcontent);                 $("#success").html(ajaxactionresult);             }         });          return false;     }); }); 

in struts.xml, have mentioned jsps each result , returning in ajax.

all returning success , getting html content. setting div id="success". results setting div.

i want display each result in appropriate div. is, if action class return string error, want set result div id="error", if it's input, result should set div id="input", similar other 1 also.

as results returning success in ajax, there no point in using error in ajax also. , not possible edit , input.

how can achieve that?

thanks

please refer : getting return value action jquery.forms.js options...mvc3

ps: change action class return json string.. , use particular key in "aftersubmit" function(response.your_key == "your_test_value") desired output.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -