Javascript 提交表单时等待消息
我想做一些非常简单的事情。我的页面上有一个按钮Javascript 提交表单时等待消息,javascript,jquery,html,forms,Javascript,Jquery,Html,Forms,我想做一些非常简单的事情。我的页面上有一个按钮 <body> <img src="images/myloadingimage.png" style="display: none;" id="loading_image"> <form id="myform" type="post" action="test.php" > Name : <input type="name" id="name" value="" /><br
<body>
<img src="images/myloadingimage.png" style="display: none;" id="loading_image">
<form id="myform" type="post" action="test.php" >
Name : <input type="name" id="name" value="" /><br />
LName : <input type="lname" id="lname" value="" /><br />
<input type="submit" id="submit" name="Submit" />
</form>
</body>
名称:
名称:
现在我想要的是当用户按下这个提交按钮。。它显示在表单提交完成之前“加载”gif动画。我想要Javascript。如何实现这一点。与jquery Ajax调用一起使用
用于显示您需要编写的加载消息
$.blockUI();
用于隐藏您需要编写的加载消息
$.unblockUI();
这个插件还有很多自定义项
希望这有帮助。与jquery Ajax调用一起使用
用于显示您需要编写的加载消息
$.blockUI();
用于隐藏您需要编写的加载消息
$.unblockUI();
这个插件还有很多自定义项
希望这有帮助。您需要手动处理表单提交事件,发出POST AJAX请求。在请求之前,您显示正在加载的图像,一旦完成,您需要再次隐藏它 检查代码,并在重要位置添加注释:
$('#myform').on('submit', function(e) {
// Prevent default browser form submission with page reload
e.preventDefault();
// Show loading indicator
var $loading = $('#loading_image').show();
// Make POST request with form parameters
$.post(this.action, $(this).serialize()).done(function(response) {
// Hide loading image once request is complete
$loading.hide();
// Do something with responce
console.log(response);
});
})
您需要手动处理FormonSubmit事件,发出POST AJAX请求。在请求之前,您显示正在加载的图像,一旦完成,您需要再次隐藏它 检查代码,并在重要位置添加注释:
$('#myform').on('submit', function(e) {
// Prevent default browser form submission with page reload
e.preventDefault();
// Show loading indicator
var $loading = $('#loading_image').show();
// Make POST request with form parameters
$.post(this.action, $(this).serialize()).done(function(response) {
// Hide loading image once request is complete
$loading.hide();
// Do something with responce
console.log(response);
});
})
只需重写默认表单操作,显示加载图标,并在成功完成ajax请求时删除 示例:
$("form").submit(function (e) {
e.preventDefault(); // stops the default action
$("#loader").show(); // shows the loading screen
$.ajax({
url: test.php,
type: "POST"
success: function (returnhtml) {
$("#loader").hide(); // hides loading sccreen in success call back
}
});
});
只需重写默认表单操作,显示加载图标,并在成功完成ajax请求时删除 示例:
$("form").submit(function (e) {
e.preventDefault(); // stops the default action
$("#loader").show(); // shows the loading screen
$.ajax({
url: test.php,
type: "POST"
success: function (returnhtml) {
$("#loader").hide(); // hides loading sccreen in success call back
}
});
});
您可以通过jQuery实现这一点 发出jQuery ajax POST请求
//Do the image load here
//now make the ajax call
$.post("test.php",$('#myform').serialize(),function(data){
//if success
//remove gif image
//continue with whatever you want
},"json");//incase you need a json reply
您可以通过jQuery实现这一点 发出jQuery ajax POST请求
//Do the image load here
//now make the ajax call
$.post("test.php",$('#myform').serialize(),function(data){
//if success
//remove gif image
//continue with whatever you want
},"json");//incase you need a json reply
我喜欢将一个div停在屏幕外,这样图像就可以预加载:
<div id="LoadingDiv" style="left: -200px;">
<div>
<img src="images/loading.gif" title="Loading" />
<div class="LoadingTitle">Loading...</div>
</div>
</div>
(这是更简单的版本)我喜欢将div停在屏幕外,这样图像就可以预加载:
<div id="LoadingDiv" style="left: -200px;">
<div>
<img src="images/loading.gif" title="Loading" />
<div class="LoadingTitle">Loading...</div>
</div>
</div>
(这是更简单的版本)如果你不想使用ajax,你可以这样做。在显示加载图标之前,如果需要,还需要为任何javascript验证添加代码
$("#submit").on("click", function(e){
$("#loading_image").show();
$("#myform").submit();
e.preventDefault();
});
如果你不想使用ajax,你可以这样做。在显示加载图标之前,如果需要,还需要为任何javascript验证添加代码
$("#submit").on("click", function(e){
$("#loading_image").show();
$("#myform").submit();
e.preventDefault();
});
你想用AJAX提交表单吗?只要我把post变量发送到test.php,如果可能的话,javascript和AJAX都要用AJAX提交表单吗?只要我把post变量发送到test.php,如果可能的话,javascript和AJAX$。默认情况下,AJAX会发出GET请求,你想要
类型:post
。是的,当我们单击“提交”按钮将变量发送到test.php时。@MedojuNarendar yes将向test.php$发出post请求。默认情况下,ajax将发出GET请求,您需要键入:post
。是的,当我们单击“提交”按钮将变量发送到test.php时。@MedojuNarendar yes将向test.php发出post请求