The Ajax callback in struts2 cannot be executed.

Source: Internet
Author: User

Recently, when jquery is used for asynchronous requests, the request is successful, but the correct JSON result cannot be returned. Call the error function with the object returned by jquery. getjson () and obtain "parsererror" with the alert error message ". Since the results were returned correctly before, after modifying the method name in the action, the method suddenly fails unexpectedly. This project is relatively large and complex. if an exception is thrown, the page will jump to the error page. However, when an asynchronous request is used, the callback function cannot be executed, so the error information cannot be located, but it was determined that there was an error during serialization, so the attribute that does not need to be serialized was added
@ JSON (serialize = false) annotation, but still fails. Locate the action on the error page and set the breakpoint and analyze the exception. invocationtargetexception is obtained, which proves that the previous speculation about serialization is correct. But why is it still a serialization error? Check the code carefully and find that the logic function name starts with get when modifying the method, which leads to the serialization of success returned by the function. Rename the method name. If it does not start with "get", restart the server and run it. The result is completely correct. When JSON is used in the summary action, only the attribute method uses get settings. Other logical methods do not start with get. Otherwise, serialization exceptions may occur.

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.