In my laravel project I have done the status Active On or OFF without any jquery or ajax. But right now i want to apply ajax. because this code take page refresh, so i don’t want the page refresh. so can anyone tell me how can I apply the ajax in this code. Here I put my route controller function and blade code. so plz tell me how to achieve this.
This is my blade
<tr><td>21</td><td>Featured Image On Home Page</td>
<td>
<a href="{{url('knowledgebasehomeImageblock')}}">
@if($settingval[0]->homeimg_block==1)
{!! '<div class ="text-success text-toggle-color"><i class="fa fa-toggle-on fa-2x" aria-hidden="true"></i>
</div>' !!}
@else
{!! '<div class="text-secondary"><i class="fa fa-toggle-off fa-2x" aria-hidden="true"></i>
</div>' !!}
@endif
</a>
</td>
</tr>
This is my route
Route::get('knowledgebasehomeImageblock','knowledgebaseSettingController@homeimageblock');
This is my controller
public function listimageblock(){
$statusvalue = DB::table('knowledgebaseSetting')->get()->toArray();
$retVal = ($statusvalue[0]->listimg_block==1) ? 0 : 1 ;
$colFeatured = array('listimg_block' =>$retVal);
DB::table('knowledgebaseSetting')->update($colFeatured);
return Redirect::back()->with('message','Display featuredblock updated successfully!');
}
2
Answers
Now I get the solution, I make some little changes in my code. This is blade file and this $settingval[0] comes from controller or you can used in blade file
And I changed the route into named route because in my case it throw an error in console so I changed into named routes
And this is my script code
for this goal you can use SSE (Server-Sent Events) in HTML 5 to get status in any moment.
with server-sent events, the updates come automatically.
your code in server side is like the following code:
for more info you can see this tutorial HTML5 Server-Sent Events