[eluser]chefnelone[/eluser]
I started again from a clean codeigniter application and I got it working but with this problem:
In the js function I must to use this line:
$.post('index.php/test/processFormAjax' , $(this).serialize() , function(html){...
But... it doesn't work if I change that line to this:
$.post( base_url + 'test/processFormAjax' , $(this).serialize() , function(html){...
or
$.post('/test/processFormAjax' , $(this).serialize() , function(html){...
or
$.post('/processFormAjax' , $(this).serialize() , function(html){...
I create this very simple example:
The example uses this code:
'test.php' Controller:
Code:
class Test extends Controller {
function Test()
{
parent::Controller();
}
function index()
{
$this->load->view('test');
}
function processFormAjax(){
echo "Data sent from the method";
}
}
test.php View
Code:
<html>
<head>
script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"> script
script
base_url = '<?php echo base_url(); ?>';
$(document).ready(function() {
$('#test').submit(function(eve) {
eve.preventDefault();
$.post('index.php/test/processFormAjax' , $(this).serialize() , function(html){
//$.post( base_url + 'test/processFormAjax' , $(this).serialize() , function(html){
alert(html);
});
});
});
script
</head>
<body>
<?php
$attributes = array('id' => 'test');
echo form_open('test/processForm', $attributes);
?>
<input type="text" name="field1" value="any value"/>
<input type="submit" value="Submit" />
</form>
</body>
</html>