问问题
3093 次
1 回答
1
尝试如下:
使用 AJAX 请求change()
为该框编写方法:select
$('select#AnswerQuestionId').on('change', function() {
var questionID = $(this).val();
// send ajax
$.ajax({
url: 'admin/answers/add/' + questionID,
method: 'get',
dataType: 'json',
success: function(response) {
// for example
// response = [{'Answer': {'id': 1, 'answer': 'ans 1'} }, {'Answer': {'id': 2, 'answer' : 2}}....];
// now loop over the response
var html = '';
$.each(response, function(index, val) {
html + = '<div id="answer_'+ val.Answer.id +'">'+ val.Answer.answer +'</div>'
});
// append this html to target container
$('#target_container').append(html);
}
});
});
在 CakePHP 方面尝试如下:
public function admin_add($id = null) {
if( !empty($id) )
{
$this->Answer->recursive = -1;
$answers = $this->Answer->find('all',
array(
'fields' => array('Answer.answer', 'Answer.id'), // assume the answer contains in answer field in db
'conditions' => array('Answer.question_id' => $id)
)
);
echo json_encode( $answers );
}
}
于 2012-09-11T11:05:30.070 回答