link jQuery UI Autocomplete plugin with CodeIgniter← Back

I wanted to use the jQuery Autocomplete plugin for a project and found that it is only capable of sending HTTP GET requests which is incompatible with the default CodeIgniter configuration. CodeIgniter requires that you only use HTTP POST’s to your controllers to submit AJAX parameters.

After trying things such as modifying the Autocomplete plugin code, I stumbled across Jami Pietila’s solution to override the default action of the plugin.

I have an input field called “stockcode” which I submit to “/ajax/stockcodesearch” which returns a json_encode‘d list of values:

    $("#stockcode").autocomplete({
      source: function(request, response) {
        $.ajax({
          url: "/ajax/stockcodesearch",
          data: { q: $("#stockcode").val()},
          dataType: "json",
          type: "POST",
          success: function(data){
            response(data);
          }
        });
      },
      minLength:2
    });

Comments

There are no comments


Post a comment