KSI Posted January 29, 2022 Share Posted January 29, 2022 Currently I'm in my controller and I have placed a check in the controller. Basically checking if the value of a particular field is 0 or not. Now if it is 0, I want to display an alert popup via my controller. To do this I've tried the following code: public function status($status){ if($this->input->post('id')){ foreach($this->input->post('id') as $key => $id): $check_emirate = $this->listings_model->check_emirate($id); if($check_emirate->emirate == 0){ echo "<script>alert('This card was not approved.');</script>"; }else{ $data=array('status'=>$status); $updated=$this->listings_model->update($data,array(),$id); } endforeach; } return true; } Now it is entering my if condition, but it doesnt show me the popup. This is the AJAX call I'm making to enable this function: $(".status").click(function(e) { chagestatus($(this)); } function chagestatus(obj){ if($('.chkbx').is(':checked') == true){ $.ajax({ type: "post", dataType: "json", async:false, url: "<?php echo site_url('listings/status'); ?>/"+obj.data('val'), data: $(".chkbx:checked").serialize(), success: function(result) {} }); } } Quote Link to comment Share on other sites More sharing options...
Solution maxxd Posted January 29, 2022 Solution Share Posted January 29, 2022 This is typically called a toast notification. For instance, if you happen to use Laravel you'd install toastr as a dependency in pacakge.json: "dependencies": { "toastr": "^2.1.4" } Create a toast component or partial: <script> @if(Session::has('message')) window.toastr.success("{{ session('message') }}"); @endif @if(Session::has('error')) window.toastr.error("{{ session('error') }}"); @endif @if(Session::has('info')) toastr.info("{{ session('info') }}"); @endif @if(Session::has('warning')) window.toastr.warning("{{ session('warning') }}"); @endif </script> Include that component/partial in your main template file: @include('components.toast') Finally, set the message in $_SESSION like so: return Response::redirect('/dashboard')->with('message', 'Data Saved!'); Obviously if you're not using Laravel you'll have to do some digging but hopefully that's a decent starting point. Quote Link to comment Share on other sites More sharing options...
KSI Posted January 29, 2022 Author Share Posted January 29, 2022 2 hours ago, maxxd said: This is typically called a toast notification. For instance, if you happen to use Laravel you'd install toastr as a dependency in pacakge.json: "dependencies": { "toastr": "^2.1.4" } Create a toast component or partial: <script> @if(Session::has('message')) window.toastr.success("{{ session('message') }}"); @endif @if(Session::has('error')) window.toastr.error("{{ session('error') }}"); @endif @if(Session::has('info')) toastr.info("{{ session('info') }}"); @endif @if(Session::has('warning')) window.toastr.warning("{{ session('warning') }}"); @endif </script> Include that component/partial in your main template file: @include('components.toast') Finally, set the message in $_SESSION like so: return Response::redirect('/dashboard')->with('message', 'Data Saved!'); Obviously if you're not using Laravel you'll have to do some digging but hopefully that's a decent starting point. Okay I think I got an idea what to use for this now. Currently using Codeigniter so the equivalent of this should be a flash message. Thanks. Quote Link to comment Share on other sites More sharing options...
maxxd Posted January 29, 2022 Share Posted January 29, 2022 Yeah, in CI it's a flash message - same general idea insofar as i recall. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.