Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How ajax submits forms across pages

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report