Javaweb Local Refresh-ajax asynchronous request SPRINGMVC display the returned JSP content instead of the IFRAME

Source: Internet
Author: User

To introduce jquery on the JSP

<script src="<%=request.getcontextpath ()%>/js/jquery_ui/jquery.js"></ Script>

Initiating a request in JS

functionGet(p) {varPatch="Show"+p; $.ajax ({//This is the $.ajax () methodType"POST", Url:patch,//The path can be in relative path, and the starting point is the path shown in the JSP where this method residesData: $ ('#myform'). Serialize (),//Ajax Submission FormDataType:"HTML",//The data type that accepts the response, my response is a page, so here's the "HTML"success:function (data) {$ ('#mydiv'). HTML (data);//I put the response page in a div to show                                    }            })        }

MyForm is a form tag in the JSP Id,mydiv is a div id,ajax to display the location of the JSP in the middle of this div, remember to add these two in the JSP

<form id="myform" method="post" >                <input id= " Hidden " name="ID" type="hidden" Value=${id} >            </form><div  id="mydiv">                            </div>

MyForm normally initiates a SPRINGMVC request, controller returns to a JSP normally

I did not do the following step, but the normal display.

Add @ResponseBody comment to the Controller's method of accepting paths

@ResponseBody// function is to send the returned object as a response to the page      "/showaj"  )          Public string Toindex (string ID, model model)        {              return"AJ";        }

Javaweb Local Refresh-ajax asynchronous request SPRINGMVC display the returned JSP content instead of the IFRAME

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.