admin管理员组文章数量:1400409
I've a simple javascript code like below and I'd like to reload page after fadeOut and fadeIn fileds but I don't know where should I put window.location.reload();
function. Do You have any suggestions ? I'm new in JavaScript.
<script>$(document).ready(function() {
$('.updateButton').on('click', function() {
var member_id = $(this).attr('member_id');
var city = $('#city'+member_id).val();
var continent = $('#continent'+member_id).val();
var country = $('#country'+member_id).val();
var id = $('#id'+member_id).val();
req = $.ajax({
url : '/deleteRequest',
type : 'POST',
data :
{city : city,continent : continent,country : country,id : id}
});
req.done(function(data) {
$('#city'+member_id).fadeOut(500).fadeIn(500);
$('#continent'+member_id).fadeOut(500).fadeIn(500);
$('#country'+member_id).fadeOut(500).fadeIn(500);
$('#id'+member_id).fadeOut(500).fadeIn(500);
});
});
});
</script>
I've a simple javascript code like below and I'd like to reload page after fadeOut and fadeIn fileds but I don't know where should I put window.location.reload();
function. Do You have any suggestions ? I'm new in JavaScript.
<script>$(document).ready(function() {
$('.updateButton').on('click', function() {
var member_id = $(this).attr('member_id');
var city = $('#city'+member_id).val();
var continent = $('#continent'+member_id).val();
var country = $('#country'+member_id).val();
var id = $('#id'+member_id).val();
req = $.ajax({
url : '/deleteRequest',
type : 'POST',
data :
{city : city,continent : continent,country : country,id : id}
});
req.done(function(data) {
$('#city'+member_id).fadeOut(500).fadeIn(500);
$('#continent'+member_id).fadeOut(500).fadeIn(500);
$('#country'+member_id).fadeOut(500).fadeIn(500);
$('#id'+member_id).fadeOut(500).fadeIn(500);
});
});
});
</script>
Share
Improve this question
asked Jul 25, 2017 at 6:43
Szymo nSzymo n
1313 silver badges10 bronze badges
2
- 2 in the done function usualy – madalinivascu Commented Jul 25, 2017 at 6:45
- end of the req done function, maybe setTimeout("window.location.reload()",2000); is better. – NicoXiang Commented Jul 25, 2017 at 6:47
5 Answers
Reset to default 2you should try
req.always(function(){
window.location.reload();
});
it will work always whether you get resonse or not.if you want to reload when you get response you can check out tutorial here.
Here is updated code that you can have a look and try. I have merged all your elements and fadeIn
has a callback, where you can refresh your page. So the page will reloaded only when the fadeIn
is pleted:
$('#city' + member_id + ',#continent' + member_id + ', #country' + member_id + ', #id' + member_id).fadeOut(500).fadeIn(500, function() {
location.reload();
});
req.done(function(data) {
$('#city'+member_id).fadeOut(500).fadeIn(500);
$('#continent'+member_id).fadeOut(500).fadeIn(500);
$('#country'+member_id).fadeOut(500).fadeIn(500);
$('#id'+member_id).fadeOut(500).fadeIn(500);
window.location = ''; // This will reload your page.
});
Put it inside a timeout function
req.done(function(data) {
$('#city'+member_id).fadeOut(500).fadeIn(500);
$('#continent'+member_id).fadeOut(500).fadeIn(500);
$('#country'+member_id).fadeOut(500).fadeIn(500);
$('#id'+member_id).fadeOut(500).fadeIn(500);
setTimeout(function(){
window.location.reload();
},TotalTimeNeededbyThheAnimationInmiliseconds)
});
});
in latest jquery
Deprecation Notice:
The jqXHR.success(), jqXHR.error(), and jqXHR.plete() callbacks will be deprecated in jQuery 1.8. To prepare your code for their
eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.
use
.done()
,.fail()
and.always()
instead ofsuccess()
,error()
andplete()
.
i believe you want to fade and hide only on ajax success so you are placing it in done()
.
if you want to reload everytime the ajax finishes use always()
eg :
req.always(function(){
window.location.reload(false);
// If we needed to pull the document from
// the web-server again (such as where the document contents
// change dynamically) we would pass the argument as 'true'.
});
or
if you want it both in done()
then
req.done(function(){
// you fadein,fadeout code
window.location.reload();
});
本文标签: javascriptReload page after function executeStack Overflow
版权声明:本文标题:javascript - Reload page after function execute - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744245539a2596993.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论