in code below, doing ajax call , calling controller '/feedback', , controller, returning string value "y". everytime, it's redirecting me error jsp.
any appreciated.
ajax call:
document.getelementbyid("modal_feedback").addeventlistener("submit", function(e) { var form = this; var name = form.name.value; var rating = form.overall.value; var msg = form.message.value; if(name == "") { alert("please enter name"); form.name.focus(); e.preventdefault(); } else if(rating == "") { alert("please select rating"); form.overall[0].focus(); e.preventdefault(); } else if(msg == "") { alert("please enter comment in message box"); form.message.focus(); e.preventdefault(); } $.ajax({ type: "post", url: "feedbackdata.htm?ratingid="+rating+"&msg="+msg, success: function(response) { console.debug(response); if(response == 'y'){ $('#contact_form').html("<div id='message'></div>"); $('#message').html("<h2>contact form submitted!</h2>") .append("<p>we in touch soon.</p>") .hide() .fadein(1500, function() { $('#message').append("<img id='checkmark' src='images/icon_pdf.png' />"); }); } } }); return false; }, false);
controller code:
@requestmapping(value = "/feedbackdata") public @responsebody string getfeedbackdata(string ratingid, string msg) throws unsupportedencodingexception{ system.out.println("inside feedbackcontroller.."); try{ feedbackservice.updatefeedback(ratingid,msg); return "y"; }catch(exception e) { logger.error("exception in login :" + e); return "n"; } } }
try updating ajax code adding datatype : "html"
accepts response string below:
$.ajax({ type: "get", url: "feedbackdata.htm?ratingid="+rating+"&msg="+msg, datatype: "html", success: function(response) { console.debug(response); if(response == 'y'){ $('#contact_form').html("<div id='message'></div>"); $('#message').html("<h2>contact form submitted!</h2>") .append("<p>we in touch soon.</p>") .hide() .fadein(1500, function() { $('#message').append("<img id='checkmark' src='images/icon_pdf.png' />"); }); } } });
also read jquery ajax
official documentation more clarification here
Comments
Post a Comment