• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI + ajax

#1
I wanted to ask if is possible to call a modal and get a value from a ajax get request. Trying to do this gives me a 500 Internal Server Error.

Thanks.
Reply

#2
No, you can't call a model, library, helper, etc, via the URL. You can only call controllers. So create a new controller, or add a method to and existing one, that will load your model and return your data when the ajax posts to it.
Reply

#3
you can only call controllers with arguments.
Reply

#4
It is possible.
TS is asking create Modal, not asking get from Model.

You can use it in view like this:
HTML and JS:
PHP Code:
<div class="bs-example">
 <!-- 
Button HTML (to Trigger Modal) -->
 <
a href="#myModal" class="btn btn-lg btn-primary" data-toggle="modal">Launch Demo Modal</a>

 <!-- 
Modal HTML -->
 <
div id="myModal" class="modal fade">
 <
div class="modal-dialog">
 <
div class="modal-content">
 <
div class="modal-header">
 <
button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
 <
h4 class="modal-title">Confirmation</h4>
 </
div>
 <
div class="modal-body">
 <
div id="ajax_content"></div>
 <
p>Do you want to save changes you made to document before closing?</p>
 <
class="text-warning"><small>If you don't save, your changes will be lost.</small></p>
 </div>
 <div class="modal-footer">
 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
 <button type="button" class="btn btn-primary">Save changes</button>
 </div>
 </div>
 </div>
 </div>
 </div>

 <script type="text/javascript">
 $(document).ready(function() {
 $.get('
<?php echo site_url(); ?>sample_modal/get_ajax_result', function(data) {
 $('#ajax_content').html(data);
 });
 });
 </script> 

Controller:
Sample_modal method get_ajax_result
PHP Code:
public function get_ajax_result() {
 echo 
'Content from ajax';
 exit();

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.