求大神解答,为什么htmlform表单提交跳转页面了,跳转不了

为什么html表单提交跳转不了页面_百度知道
为什么html表单提交跳转不了页面
我有更好的答案
无图无真相啊!
为您推荐:
其他类似问题
您可能关注的内容
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。form表单只提交数据而不进行页面跳转的解决方案
转载 & & 作者:
将数据提交到saveReport(form的action指向)页面,但是页面又不进行跳转,即保持当前页面不变呢?利用jquery的ajaxSubmit函数以及form的onsubmit函数完成
一般的form提交操作写法为
代码如下: &form action="saveReport.htm" method="post"& …… &input type="submit" value="保存报告"/& &/form&
点击submit按钮或直接回车可以将数据提交到saveReport页面,但是提交后也会跳转到saveReport页面 如何做到 将数据提交到saveReport(form的action指向)页面,但是页面又不进行跳转,即保持当前页面不变呢?? 这种需要在load一个页面的时候尤其迫切。 利用jquery的ajaxSubmit函数以及form的onsubmit函数完成,如下:
代码如下: &form id="saveReportForm" action="saveReport.htm" method="post" onsubmit="return saveReport();"& &input type="submit" value="保存报告"/& &/form&
form增加一个id用于在jquery中调用,增加一个onsubmit函数用于submit前自己提交表单 saveReport对应函数为
代码如下: function saveReport() { // jquery 表单提交 $("#showDataForm").ajaxSubmit(function(message) { // 对于表单提交成功后处理,message为提交页面saveReport.htm的返回内容 });
// 必须返回false,否则表单会自己再做一次提交操作,并且页面跳转 }
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具6被浏览5,914分享邀请回答&script&location.href="path/to/your/page"&/script&
如果用ajax可以完全解耦,请自行查找jQuery文档ajax。也可以直接使用XMLHttpRequest:来源:&script type="text/javascript"&
function loadXMLDoc(url)
if (window.XMLHttpRequest)
{// code for all new browsers
xmlhttp=new XMLHttpRequest();
else if (window.ActiveXObject)
{// code for IE5 and IE6
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if (xmlhttp!=null)
xmlhttp.onreadystatechange=state_C
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
alert("Your browser does not support XMLHTTP.");
function state_Change()
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = OK
// ...our code here...
//location.href="path/to/your/page";
alert("Problem retrieving XML data");
0添加评论分享收藏感谢收起写回答怎么让Form提交表单当前页面刷新不跳转-html教程-ab蓝学网
本文为大家介绍下使用Form提交表单后页面刷新不跳转的实现,感兴趣的朋友可以了解下1、设计源码代码如下:&!DOCTYPEhtmlPUBLIC"-//W3
本文为大家介绍下使用Form提交表单后页面刷新不跳转的实现,感兴趣的朋友可以了解下
1、设计源码&
&!DOCTYPE html PUBLIC &-//W3C//DTD XHTML 1.0 Transitional//EN& &http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&&&
&html xmlns=&http://www.w3.org/1999/xhtml&&&
&meta http-equiv=&Content-Type& content=&text/ charset=utf-8& /&&
&title&Form提交表单页面不跳转&/title&&
&form action=&& id=&& method=&post& target=&id_iframe&&&
&input type=&text& id=&input_text& name=&input_text&/&&
&input type=&submit& id=&sobmit& name=&submit& value=&提交& /&&
&iframe id=&id_iframe& name=&id_iframe& style=&display:&&&/iframe&&
2、运行结果&
(1)输入“451”,单击“提交”&
(2)输入“”,单击“提交”&
页面提交刷新,不跳转
上编:下编:
本月热门的内容
1 2 3 4 5 6 7 8 9 10
最近更新的内容在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。
问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
&div id="registerBox" style="display: none"&
&div class="title"&注册&/div&
&form action="/api/user/register" method="post"&
&div class="line"&
&span&用户名:&/span&
&input type="text" name="username"&
&div class="line"&
&span&密码:&/span&
&input type="password" name="password"&
&div class="line"&
&span&确认:&/span&
&input type="password" name="repassword"&
&div class="line"&
&input type="submit" name="submit" value="注册"&
&div class="line"&
&p&已有账号?&a href="javascript:;"&马上登录&/a&&/p&
api.post('/user/register', async(ctx) =& {
var username = ctx.request.body.username,
password = ctx.request.body.password,
repassword = ctx.request.body.
//检测用户名是否为空
if(username === ''){
responseData.code = 1;
responseData.message = '用户名不能为空';
ctx.body = responseD
//检测密码是否为空
if(password === ''){
responseData.code = 2;
responseData.message = '密码不能为空';
ctx.body = responseD
//检测密码是否一致
if(password !== repassword){
responseData.code = 3;
responseData.message = '密码输入不一致';
ctx.body = responseD
//检测用户名是否已被注册
await new Promise(function(resolve, reject){
User.findOne({'username': username}, function(err, doc){
//表示数据库中有纪录
responseData.code = 4;
responseData.message = '用户名已被注册';
resolve(responseData);
//保存用户消息到数据库
var user = new User({'username': username, 'password': password});
user.save();
responseData.code = 0;
responseData.message = '注册成功';
resolve(responseData);
reject(err);
表单提交后会切换到/api/user/register页面,请问如何阻止他跳转页面并将responseData.message显示到页面上?
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
给&form action="/api/user/register" method="post" onsubmit = "return false"& 加个return false,阻止表单跳转
或者 &input type="submit" name="submit" value="注册"& 把这里的type="button",这里是submit 所以会自动使表单提交;
分享到微博?
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。

我要回帖

更多关于 form表单提交不跳转 的文章

 

随机推荐