Solution to the Ajax return validation is always a way to eject error errors _ajax related

Source: Internet
Author: User

Send a simple case:
Front desk:

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >  

Background:

public class Login_do extends HttpServlet {public 
  void doget (HttpServletRequest request, HttpServletResponse Response) 
      throws Servletexception, IOException { 
      this.dopost (request, response); 
  public void DoPost (HttpServletRequest request, httpservletresponse response) 
      throws Servletexception, IOException { 
    request.setcharacterencoding ("UTF-8");  
    Response.setcharacterencoding ("UTF-8"); 
    String name =request.getparameter ("name"); 
    String Password = request.getparameter ("password"); 
    String js = "{\" name\ ": name,\" password\ ":p Assword}"; 
    PrintWriter out = Response.getwriter (); 
    Jsonobject json = new Jsonobject (); 
    Json.put ("name", name); 
    Out.print (Json.tostring ()); 
    Response.getwriter (). Write (json.tostring ()); 

When you click on login:

Workaround: There are two possible ways to eject the error message:
First:URL error, the background is not directly to the value of
You can use Firefox's firebug to view: If you respond to information, this is not the problem, then there may be the second case :
Error returning data type:
In my case, the returned data was accidentally printed two times, so just delete one sentence:

Out.print (Json.tostring ()); 
Response.getwriter (). Write (json.tostring ());  

caused an error. The information displayed in Firebug is:

The above is for you to analyze the use of Ajax to return validation when the error always pops up, I hope to solve such problems to help.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.