jquery - Call specific controller from JSON in CodeIgniter -



jquery - Call specific controller from JSON in CodeIgniter -

there code:

var formobject = { run : function(obj) { if (obj.val() === '') { obj.nextall('.update').html('<option value="">----</option>').attr('disabled', true); } else { var id = obj.attr('id'); var v = obj.val(); jquery.getjson('update.php', { id : id, value : v }, function(data) { if (!data.error) { obj.next('.update').html(data.list).removeattr('disabled'); } else { obj.nextall('.update').html('<option value="">----</option>').attr('disabled', true); } }); } } }; $(function() { $('.update').on("change", function() { formobject.run($(this)); }); });

i need phone call specific controller in order populate select form automatically. in line of code calling url:

jquery.getjson('update.php', { id : id, value : v }, function(data)

i possible phone call codeigniter view instead 'update.php' file, or have in other way? thanks.

class controller{ public function mymethod(){ //make sure ajax request if(!$this->input->is_ajax_request()) { show_error('invalid request'); return; } if(!$this->input->post('id') or !$this->input->post('val')) { echo(json_encode(array( 'error' : 1 ))); return; } $query_from_db = ''; //mysql query ? if( $query_from_db ) { //send browser, no view homecoming $this->output ->set_content_type('application/json') ->set_output(json_encode($query_from_db)); } } } /** * set global var in main view * avail files **/ var site = "<?=site_url()?>"; /** somefile.js **/ ;(function($){ var formobject = { init : function(){ if($("#formid")) this.run();//only load if form specific id exists }, run : function(){ //limited nested functions //only execution var update = function(obj){ //check empty value if(obj.val() == '') { obj.nextall('.update').html('<option value="">----</option>').attr('disabled', true); return; } var info = { id : obj.attr('id'), val : obj.val() }; homecoming doajax(data); //doajax function execution }; var doajax = function(data){ homecoming $.getjson( site + "controller/mymethod", data, function(callback){ if(callback.error) { obj.nextall('.update').html('<option value="">----</option>').attr('disabled', true); return; } obj.next('.update').html(callback.list).removeattr('disabled'); }); }; $('.update').on("change", function() { update($(this));//update function execution }); } } $(function(){ formobject.init(); }); })(jquery);

jquery json codeigniter

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -