2016-03-18 12 views
0

JS前に2秒間MSGを表示する方法:window.locationの

$.ajax({ 
    url: url, 
    method: 'POST', 
    data: data, 
    }).done(id => { 
    this._handleMsg('data saved.'); 
    const newUrl = dutils.urls.resolve('test', { test_id: id }); 
    window.location.replace(newUrl); 
    }).fail((jqXHR, textStatus, errormsg) => { 
    this._handleError('Sorry. Report not saved. Reason:' + errormsg); // eslint-disable-line no-alert 
    }); 



_handleMsg(msg) { 
    if (msg) { 
     $('#header .form-group').addClass('has-msg'); 
     $('.report-error').html(msg).delay(200000).fadeIn(500000); 
    } else { 
     $('#header .form-group').removeClass('has-msg'); 
    } 
    }, 

SCSS: "データが保存され、" 私は、メッセージを表示する必要が

.report-error{ 
    visibility: hidden; 
    text-align: center; 
    color: red; 
} 


.has-msg, .has-msg:focus, .has-msg:hover{ 
    input { 
     border-color: #843534; 
     -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #ce8483; 
     box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #ce8483; 
     background-color: #ffffff; 
     outline: 0; 
    } 
    label, .report-error{ 
     visibility: visible; 
     color: green; 
     font-size:30px; 
    } 
} 

2秒間、別のURLにリダイレクトします。 $( '。report-error').html(msg).delay(200000).fadeIn(500000);は機能しません。

おかげ

UPDATE

203   this._handleMsg('data saved.'); 
204   setTimeout(()=>{ 
205   const newUrl = dutils.urls.resolve('test', { test_id: id }); 
206   window.location.replace(newUrl); 
207   }, 2000); 
+0

setTimeout()を使用していますか? – wawawoom

答えて

0

には、JavaScriptのタイムアウトを試してみてください:ここでsetTimeout()look here for more infos

a fiddle using setTimeoutとパラメータで関数を呼び出すことです。

次のようにコード自体は次のとおりです。

function alertMessage(firstMessage, secondMessage) { 
    alert(firstMessage + ' ' + secondMessage); 
} 

setTimeout(
    alertMessage, // name of the function to be called after the delay 
    1000, // the size of the delay in ms 
    'Hello world!', // the first parameter to be parsed to the called function 
    'You rock!' // the second parameter to be parsed to the called function 
); 

私はこのことができます願っています。

+0

setTimeout(this._handleMsg( 'Report saved。')、6000); ???? 6秒間続くことはできないようです。 – BAE

+0

setTimeout(function(){handleMessage( 'Message saved');}、6000); – Sommereder

+0

私が道を離れると、私はフィドルを書くでしょう。 – Sommereder

0
$.ajax({ 
    url: url, 
    method: 'POST', 
    data: data, 
    }).done(id => { 
    this._handleMsg('data saved.'); 
    const newUrl = dutils.urls.resolve('test', { test_id: id }); 
    //below function will call after 2s that solve your purpose 
    setTimeout(function() { window.location.replace(newUrl); }, 2000); 

    }).fail((jqXHR, textStatus, errormsg) => { 
    this._handleError('Sorry. Report not saved. Reason:' + errormsg); // eslint-disable-line no-alert 
    }); 
関連する問題