5
I’m not able to pass a string in the format JSON
for a controller
of Codeigniter via AJAX.
A string JSON:
var avaliacao= {"avaliacao":[{"pergunta":"Qual sua idade?"}[{"resposta_certa":"99","resposta_err1":"11","resposta_err2":"15",
"resposta_err3":"14","resposta_err4":"27"}]]}
THE JS:
var controller = 'endereco/controller';
var base_url = 'dominio/do/site';
function grava_avaliacao(){
jQuery.ajax({
url : base_url + '/' + controller + '/add',
type : 'POST',
data : avaliacao,
dataType: 'json',
success : function(data){
alert(data);
}
});
}
The controller:
public function add(){
var_dump(json_decode($this->input->post('avaliacao')));
}
Is this json correct? Try jsonlint.com or others to test, this could be it.
– Marcelo Diniz