레코드를 가져오고 싶습니다. 아약스를 사용하여보기에 표시하려고합니다. 여기 나는 json 데이터를 얻을 수 없었다. 그리고 제가 알기 만하면, 적절한 견해로 전달할 방법은 무엇입니까. 이를 통해 표에서 사용자 이름과 주석을 가져와 아약스를 사용하여 click 이벤트에 대한보기에 표시하려고합니다. 처럼 사용자가 댓글을 달았 으면 페이지로드없이 댓글이 표시됩니다.데이터베이스에서 레코드를 가져올 수없고 아약스를 통해보기에서로드 할 수 없습니다.
컨트롤러 :
public function get_comments()
{
$query=$this->db->query("SELECT user_name,comments FROM user_comments join user_reg where user_reg.user_id=user_comments.user_id");
$temp = $query->result();
foreach($temp as $row)
{
header('Content-Type: application/json');
echo json_encode($row);
}
exit();
}
보기 : 당신은 루프의 당신의 "에코로 json_encode"외부를 넣어 시도해야
<form action="" method="post" name="usercomments" id="usercomments">
<div>
<textarea name="comment" form="usrform" placeholder="Enter comment here..." id="ucom"></textarea>
</br>
<div class="tab-group">
<input type="submit" class="button button-block tab" id="submitbutton" value="Comment"/>
</div>
</div>
</form>
$(document).ready(function()
{
$("#submitbutton").click(function(event)
{
//alert('hiii');
event.preventDefault();
jQuery.ajax({
type:"POST",
url:"<?php echo base_url();?>index.php/welcome/get_comments",
dataType:"json",
data:"",
success:function(data)
{
console.log(data);
alert(data);
}
});
});
});
양식을 제출하면 어떻게됩니까? 콘솔에서 오류가 발생합니까? 응답으로 서버 측 오류가 발생합니까? 여기에 충분한 정보가 없습니다. – wrxsti
양식을 제출하면 레코드가 삽입되지만 가져올 수 없습니다. 어떤 에러도없고 콘솔에서도 정보를 얻을 수 없었습니다. – Viral