[英]convert the string in servelt to json data and pass it to javascript : ajax
I need to submit a form in ajax manner.我需要以 ajax 方式提交表单。 when form submits convert the string inside the servlet to json data and pass it to the javascript function and display these errors separately near to the error div tag below each input field.当表单提交时,将 servlet 中的字符串转换为 json 数据并将其传递给 javascript 函数,并在每个输入字段下方的错误 div 标记附近分别显示这些错误。
if(firstparamtr-condition)
{
String firsterror = "Error first";
response.setContentType("application/json");
response.setHeader("Cache-Control", "no-cache");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(firsterror);
}
if(secondparamtr-condition)
{
String seconderror = "Error second";
response.setContentType("application/json");
response.setHeader("Cache-Control", "no-cache");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(seconderror);
}
javascript code javascript代码
posting.done(function( responseText ) {
alert(responseText);
//HERE I need to separate the responseText and show that errors in the div tags named 'firstEr' and 'secondEr'
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.