CI+JQuery+Ajax problem
- by Sadat
Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value. But using ajax it doesnt work.
Following are the code segment, i have just started with JQuery+Ajax with CI.
Here is my controller:
<?php
class BaseController extends Controller{
public function BaseController(){
parent::Controller();
$this->load->helper('url');
}
function index(){
$this->load->view('header');
$this->load->view('body');
$this->load->view('footer');
}
function ajaxTest($testData=""){
$this->load->view('ajaxtest',array('test_data'=>$testData));
}
}
?
Here is View
<?php
echo $test_data;
?
Ajax Call Function
function testAjaxCall(){
$.get(
base_url+'basecontroller/ajaxtest/test-value',
function(responseData) {
$("#test-div").html(responseData);
}
);
}
Ajax Calling Page(button)
<div id="test-div"></div><input type="button" onclick="testAjaxCall()" name="ajax-test" value="Test Ajax" />
JS base_url declaration
<script type="text/javascript" src="<?php echo base_url();?>js/jquery.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>js/application-ajax-call.js"></script>
<script type="text/javascript">
/* to make ajax call easy */
base_url = '<?php echo base_url();?>';
</script>