【发布时间】:2014-01-12 22:59:58
【问题描述】:
所以基本上我在 javascript 中有一个两项数组,它是根据用户单击的链接生成的。我正在尝试将此数组发送到我的控制器,然后发送到模型。模型将查看数组并将其中一项与特定列/行匹配,并选择性地显示数据。
我在将数据从 AJAX 传递到我的控制器时遇到问题。
AJAX 代码(在 .js 文件中)
$('#youmax-video-list-div').append('<div id="testing1"></div>');
$('#concept').click(function(){
console.log(course);
$.ajax({
url: 'http://localhost:8888/index.php/trial/getValues',
type:'POST',
dataType: 'json',
data:'',
error: function(){
$('#testing1').append('<p>goodbye world</p>');
},
success: function(result) {
var htmlStr = '';
$.each(result, function(a, b){
htmlStr += b.qText + '<br />';
});
$('#testing1').append(htmlStr);
} // End of success function of ajax form
}); // End of ajax call
});
我假设我必须对数据字段做一些事情,但我不知道它的语法。
chrome 中的控制台登录出现了这个:
数组[2] 0:“PL8G0kdHFfE3WuyevUDvwSYCZw8mp8LBFA” 1:“PL8G0kdHFfE3V62Jp2ju-PelOaNUkH7xR8”
控制器
function getValues(){
$this->load->model('get_db');
$data = $this->get_db->getAll();
$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($data));
return $data;
}
型号
class Get_db extends CI_Model{
function getAll(){
$query=$this->db->query("SELECT * FROM questions");
return $query->result();
//returns from this string in the db, converts it into an array
}
}
正如我之前所说,我真的只关心将数据发送到我的控制器和模型。 数组的名称是“课程”。但是,console.log 中似乎并非如此。这只是 chrome 的作用吗?
【问题讨论】:
标签: ajax codeigniter model controller