buat di controller seperti coding ini
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class ciJson extends CI_Controller {
public function index()
{
$this->load->view('ajax_post_view');
}
public function save(){
$data = "josjes";
echo json_encode($data);
}
}
===================================
buat view seperti dibawah ini :
===================
<script type="text/javascript" src="<?php echo base_url()?>/assets/js/jquery.min.js"></script>
<div><button id="buttin">kilik</button></div>
<div id="ajaxView"></div>
<script type="text/javascript">
$(document).ready(function(){
$('#buttin').click(function(){
$.ajax({
url : "<?php echo site_url('cijson/save')?>"
type : "POST",
//url : "<?php echo base_url(); ?>" + "index.php/cijson/save",
dataType : 'json',
data : {},
success : function(res){
alert(res);
}
});
});
});
</script>
Langganan:
Posting Komentar (Atom)
0 Response to "ajax codeigniter sederhana"
Posting Komentar