• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help with ajax, cant get it work :/

#1
[eluser]nanetorg[/eluser]
Hi all!
I just finish read this articles
http://www.weblee.co.uk/2009/06/10/simpl...er-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;
    }
   }
  });


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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