javascript - Laravel 5 how to get controller display simple message box or alert? -
cannot find solution simple problem, voting app, , if users votes show simple alert "thanks" , cannot find way controller? have tried simple jquery code it's not working.
echo "<script>alert('you have voted');</script>";
any simple solutions?
public function voting() { $ip=$_server['remote_addr']; $id = input::get('msg_id'); $vote = input::get('vote'); $count = voting::wheremes_id_fk($id)->whereip_add($ip)->count(); if($count==0) { if($vote == "up") { project::whereid($id)->increment('up'); voting::insert( array('mes_id_fk' => $id, 'ip_add' => $ip ) ); } else if ($vote=="down") { project::whereid($id)->decrement('down'); voting::insert( array('mes_id_fk' => $id, 'ip_add' => $ip ) ); } } else { // how popup "thanks" alert?? } }
if using ajax vote, return json
response , use javascript
respond json
response.
example:
public function vote() { //your voting code return response::json(['success'=>true]); }
and in javascript
, check json
$.post('/vote/', { id: 123 }, function(data){ if(data.success== true) { alert('thanks voting); } }
if not using ajax, use session flash.
i.e., controller,
public function vote() { //your voting code session::flash('msg', 'thanks voting'); return redirect::back(); }
and view,
@if(session::has('msg')) {{session::get('msg')}} @endif
Comments
Post a Comment