从Javascript调用成功对话框



我想用Javascript从Laravel调用成功或错误对话框!我有一个Ajax Post请求,如下所示:

$.post('/tutorials/rate', {id:tutID, rating : rating});

如何从Ajax方法调用对话框?!在我的控制器中,我总是这样做:

return Redirect::to('/tutorials/show/' . $postId)->with('success', 'Successfully Rated!');

编辑:我的问题是如何称呼这条线:

return Redirect::to('/tutorials/show/' . $postId)->with('success', 'Successfully Rated!');

使用Javascript!

通过添加解决了问题

    $.pnotify({
title: 'No Icon Success',
text: 'I have no icon.',
type: 'success',
icon: false
});

您可以这样称呼它:

$.ajax({
  type: 'POST',
  url: '/tutorials/rate',
  data: parameters,
  success: function(){
    alert('success');
  },
  error: function(){
    alert('failure');
  }
});

因为jQuery没有标签,但您使用的是$.post,这是jQuery的函数之一,所以我将假设这一点,除非另有说明。

.post有第三个可选参数,您可以在其中设置回调函数,可以使用函数的名称,也可以使用匿名函数。

$.post('/tutorials/rate', {id:tutID, rating : rating},function(dialogHTML){
   //Do whatever code shows your dialog
   var dlg = jQuery(dialogHTML);
   jQuery('body').append(dlg);
   dlg.fadeIn();
},'html');

$.post('/tutorials/rate', {id:tutID, rating : rating},myCallback);
function myCallback(dialogHTML) {
   //Do whatever code shows your dialog
   var dlg = jQuery(dialogHTML);
   jQuery('body').append(dlg);
   dlg.fadeIn();
}

jQuery.post-api

最新更新