AJAX in Codeigniter

I am writing my first Codeigniter application, and I would like to use AJAX to get some information for a modal window. Can someone help me through an easy way to enable ajax w / CI?

In particular, the user clicks on the link and instead of being transferred to another page, this page will be loaded into the modal block.

Thank!

+3
source share
1 answer

Answering your question, and since CI does not seem to have implemented proper javascript library support, you can use such a function to ensure that the information you're dealing with comes from ajax:

http://snipplr.com/view/1060/check-for-ajax-request/

, javascript, jQuery MoonTools

, , $this- > input- > post ('field') $this- > input- > get (' '), .

( jquery), , , :

$(function() {

  $('a.delete').click(function(e) {
  // prevents the default behaviour of the anchor
  e.preventDefault();
  // gets the id stored in the anchor as attribute
  var cid= $(this).attr('cid');

  // instantiate and executes the ajax
  $.ajax({
    type: 'POST',
    url: 'http://www.yoursite.com/ajax.php',
    data: "action=delete&cid="+cid,
    async: true,
    success: function(data){
    // alerts the response, or whatever you need
    alert(data);
  }
  });
});

CI . , url ajax (url , ) , url-url-url-, , " url: ajax URL-.

+4

Source: https://habr.com/ru/post/1725129/


All Articles