$ .ajax仅在置于alert()时有效

编程入门 行业动态 更新时间:2024-10-27 11:25:46
本文介绍了$ .ajax仅在置于alert()时有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试在以前使用AJAX加载的内容中加载内容。我把代码

I tried to load content inside content those are loaded previously with AJAX. I put the code

加载():

jQuery("#contentpage").on("submit", "#loginform", my = function() { $("#contentpage").load("/logincheck.jsp"); alert("this is required "); });

与$ .ajax():

jQuery("#contentpage").on("submit", "#loginform", function() { $.ajax({ url: '/logincheck.jsp', success: function(data) { $('#contentpage').html(data); } }); alert("this is required "); });

#loginform 是一个加载的HTML表单之前的AJAX请求,我成功访问了 .on()函数。

#loginform is a HTML form loaded with previous AJAX request, I successfully access in with .on() function.

但问题是当我提交 #loginform 而放 alert('这是必需')框然后刷新整个页面。 #contentpage 内的内容也没有变化。

But the problem is when I submit #loginform without putting alert('this is required') box then its refreshing the whole page. Also content inside #contentpage are also not changing.

但是,如果我按照警告(这是必需的)执行相同操作,其工作正常,内容正在加载 #contentpage 而不刷新整个页面。

But if I do the same with putting alert("this is required"), its working fine, contents are getting loaded in #contentpage without refreshing whole page.

这是一个时间问题吗? Ajax请求需要时间,而且它是异步的?如果我错了,请纠正我。

Is this a timing issue? Ajax request takes time and it's asynchronous? Please correct me if I am wrong.

推荐答案

你试过这个吗?

jQuery("#contentpage").on("submit","#loginform",my=function(event){ event.preventDefault(); $("#contentpage").load("/logincheck.jsp"); alert("this is required "); });

这至少应该阻止页面刷新,也可以解决其他问题。祝你好运!

This should at least stop the page from refreshing and may sort out the other problems as well. Good luck!

更多推荐

$ .ajax仅在置于alert()时有效

本文发布于:2023-11-13 21:37:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585386.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ajax   alert

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!