CodeIgniter Forums
need help with ajax, cant get it work :/ - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: need help with ajax, cant get it work :/ (/showthread.php?tid=48194)



need help with ajax, cant get it work :/ - El Forum - 01-07-2012

[eluser]nanetorg[/eluser]
Hi all!
I just finish read this articles
http://www.weblee.co.uk/2009/06/10/simple-jquery-ajax-with-codeigniter-part-4/

and I still can pass variables from form to my controller using ajax :/

here is my controller:
Code:
public function check() {
  // secure
  if (!$this->input->is_ajax_request()) redirect(base_url());
  
  // vars
  $callback = ''; // here i want a value of input in my form on view page
  
  
  // valid
  
  // output
  echo $callback;
}

here view:
Code:
<form action="<?php echo base_url(); ?>upload" method="post" enctype="multipart/form-data" id="upload-form">
      <div class="show_upload" id="upload-local">
        &lt;input type="file" name="file_local" value="" /&gt;
      </div>
      <div class="hide_upload" id="upload-remote">
          &lt;input type="text" name="file_remote" value="" /&gt;
      </div>
      <a id="upload-button"><span>Upload</span></a>
    &lt;/form&gt;
and here my ajax code:

Code:
var upload_url = '&lt;?php echo base_url(); ?&gt;upload/check';
var upload_form = "#upload-form";
  $.ajax({
   url: upload_url,
   type: 'post',
   data: $(upload_form),
   dataType: 'html',
   success: function(callback) {
    if (callback !== '') {
     html = '<div><a class="box error corners"><span class="close">&nbsp;</span>' + callback + '</a></div>';
     $(info_box).append(html);
     $(info_box).slideDown(slide_delay);
    }
    else {
     $(upload_form).submit();
     return false;
    }
   }
  });