0

我制作了一个 POST 表单并通过 ajax 发送数据,我使用 PNotify 来提醒问题是我如何刷新页面并保留通知框。或者我如何在提交按钮后将用户重定向到另一个页面并通知框保留?我尝试location.reload()成功:功能但不起作用...通知未显示。

<script type="text/javascript">
var frm = $('#editticket');
frm.submit(function (ev) {
  $.ajax({
    type: frm.attr('method'),
    url: frm.attr('action'),
    data: frm.serialize(),
    success: function (data) {
      new PNotify({
        text: 'Task edited.',
        type: 'info',
        hide: false
      });
    }
  });  
  ev.preventDefault();
});
</script>                            
4

1 回答 1

1

您需要一些代码来在页面加载时创建一个新的 PNotify 实例。简单的方法是使用传递参数location.hashhttp://jsfiddle.net/SEVUL/7/

function notify() {
    var hash = window.location.hash;

    if(~hash.indexOf('!PNotify')) {
        new PNotify({text: hash.replace('#!PNotify:', '')});
        location.hash = "";
    }
};

function reload(text) {
    var location = window.location;

    location.hash = "!PNotify:" + text;
    location.reload();
}

$(notify);

$(function() {
    $('#reload').click(function() {
        reload('Some useful info');
    });    
})
于 2014-05-31T11:58:36.710 回答