jquery - Laravel 4 controller method call from Ajax -


since no means ajax guru, have come here see if lead me in right direction information on trying do. have scoured looking information either don't understand reading, or it's not looking do. honestly, don't know if trying possible, yeah...

basically, trying accomplish putting application in maintenance mode admin section of site. using jquery .click() function update #div, want call function controller @ same time.

so here goes...

my jquery right is:

$('#on').click(function () {     $('#turnedon').addclass('green');     $.cookie('maint', 'maintenance', {         expires: 365     });     //alert('you have put app in maintenance mode.');     $.ajax({         method: 'get',      // should use post? or get? wanting run function when .click() function run         url: '/admins',     // not sure should used url since want call function         error: function(e){             alert( 'error ' + e );             }         });          }); 

i not sure whether should use or post method since calling method controller.

the function calling in controller:

public function getmaintenanceon() {   if(request::ajax()) {     artisan::call('down');   } } 

and in routes:

route::get('/admins', array('uses' => 'admincontroller@getmaintenanceon')); 

i have set in global.php file admins can access site when it's in maintenance mode. if put application down using terminal, can still access admin need to, rather able put app in maintenance mode without having go in , change routes on hosting files.

thanks in advance!

looks have problem in javascript, here, $.cookie gave me error, removing worked fine. did test:

a route:

route::get('admins', function()  {     log::info("route!");      if (request::ajax()) {         log::info("ajax");          artisan::call('down');     } }); 

a button:

enter code hereshut down

and javascript without cookie:

<script>      $('#on').click(function () {         alert('you have put app in maintenance mode.');         $('#turnedon').addclass('green');         $.ajax({             method: 'get',      // should use post? or get? wanting run function when .click() function run             url: '/admins',     // not sure should used url since want call function             error: function(e){                 alert( 'error ' + e );                 }             });              });  </script> 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -