How ajax submits forms across pages
This article will explain in detail how to submit forms across pages in ajax. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
As mentioned earlier, the problem of repeatedly submitting a form, in addition to dealing with token password verification and redirection, another frequently used method is that the new page handles the form submission, closes the current page when finished, and refreshes the previously requested page.
ArtDialog.js is used here
1. File structure
2 、 user.jsp
User list function openA () {window.open ("/ MySSH2/user/manage_addUI");} add user
4 、 UserManageAction.java
Package com.myssh3.action; import java.io.IOException; import java.io.PrintWriter; import javax.annotation.Resource; import javax.servlet.ServletException; import org.apache.struts2.ServletActionContext; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import com.myssh3.bean.User; import com.myssh3.service.UserService; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; @ Controller @ Scope ("prototype") public class UserManageAction extends ActionSupport {@ Resource UserService userService; private User user Public User getUser () {return user;} public void setUser (User user) {this.user = user;} public String addUI () {return "add";} public void add () throws ServletException, IOException {ServletActionContext.getResponse (). SetContentType ("text/html;charset=utf-8"); PrintWriter out = ServletActionContext.getResponse (). GetWriter (); try {userService.addUser (user); ActionContext.getContext (). Put ("message", "saved successfully") Out.write ("{\" success\ ": true}");} catch (Exception e) {e.printStackTrace (); out.write ("{\" success\ ": false,\" msg\ ":\" error\ "});}
Page effect
Use $('# userForm') .serialize () when submitting the form; serialize the form data
Window.opener.art.dialog ({time:2,content:' saved successfully'}); return the page that uses window.open (or parent page) and call the artDialog plug-in to close dialog at a fixed time
SetTimeout (function () {window.opener.location.reload ();}, 3); using a timer to refresh a page using window.open (or as a parent page), the time setting problem of dialog and reload needs to be readjusted.
This is the end of the article on "how to submit forms across ajax pages". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.