[eluser]MaartenDeGroote[/eluser]
Hi All,
I also recently started using CodeIgniter. Up until now I really have been loving it.
However, I also seem to run into some small problems when using a POST $.ajax in jQuery. I was wondering if someone has run into the same problem before and knows an appropriate solution.
I created a simple form and use the serialize function from jQuery and the $.ajax method to submit the info to the controller. This looks like this:
Code:
$(document).ready(function(){
$("form").submit(function(){
var str = $(this).serialize();
$.ajax({
type : "POST",
url : "ajax/form",
data : str,
success : function(msg){
alert(msg.message)
}
}, "json");
return false;
});
});
Subsequently, the form method in the ajax class handles the request as following:
Code:
<?php
class Ajax extends Controller{
function _construct(){
parent::Controller();
}
function form(){
$array = array("message" => "test");
$result = json_encode($array);
echo $result;
}
}
No matter what I do, the return is always "undefined". I have been using this method earlier, before I was using CI so I figured there is something that I might have misconfigured in CI.
Any ideas? All help is appreciated!
Kind regards,
Maarten