Ajax requests are always unsuccessful after they are submitted to the controller.
During my internship recently, I sent an ajax request to the controller background in js when I clicked the query. However, no matter what happens, the request address is correct because the system is used in the background. out. println output has a value, and it does return, and then Baidu found it in springmvc annotations. the @ ResponseBody annotation must be added before the ajax request is successful.
Some background code:
@ RequestMapping ("select. do ") @ ResponseBody // Add ResponseBody before the return value is returned. The ajax request can be successful. public String selectByDate (HttpServletRequest request, Model model) {String begin_Date = request. getParameter ("begin_Date"); List <MobileManage> list = getDataList (begin_Date); JSONArray json = JSONArray. fromObject (list); String paseJson = paseJson (list); // System. out. println (json. toString (); return paseJson;} View Code
Front-end code:
$. Ajax ({type: "post", url: "/mylog/mobileManage/select. do ", dataType:" json ", data: {begin_Date: begin_Date}, success: function (data) {// processing}) View Code