如果ajax成功与否,我想显示一条消息。 该代码到目前为止,但我想添加一些消息。Laravel Ajax显示消息
我的控制器删除功能:
public function destroy(Request $request, $streamID = 0)
{
$stream = Stream::find($streamID);
if($stream)
{
$stream->delete();
File::delete($stream->image);
return redirect()->route('stream.index')->with('success', 'Hooray');
}
else
{
return redirect()->route('stream.index')->with('success', 'Not Hooray');
}
}
而阿贾克斯成功和错误部分:
success: function(data) {
// show message?
},
error: function(data) {
// show message?
}
而且怎么能帮到你?告诉你关于'alert'的功能吗? –
你可以使用Flash数据https://laravel.com/docs/5.4/session#flash-data – mfgabriel92
而不是返回redirect() - > route('stream.index') - > with('success','Hooray '); return response() - > json(['success'=>'Hooray']); – sunilwananje