PHP-CI - Ajax

摘要:PHP CI - Ajax

PHP

    public function ajaxTest() 
    {
        header("Content-Type:application/json; charset=utf-8");
        date_default_timezone_set("Asia/Taipei");   

        $id    = $this->input->post("id", TRUE);

        $result = array();

        ob_clean();
        echo json_encode($result);  
    }

HTML - JavaScript

<script language="javascript" type="text/javascript">
	function ajaxTest(source) {
		var $btnSource = $(source);
		var id = $btnSource.attr('id');
		var url  = "<?php echo base_url(); ?>Test/Test/ajaxTest";
		var data_v = {"id":id};

        $.post(url,
        	   data_v,
        	   function (data) {
		            alert(JSON.stringify(data));
	            }  
        );
	}
</script>