Reputation: 935
My js script
jQuery(".unblock").click(function(){
var num = jQuery('.page.active').text();
var ban_id = jQuery(this).attr('id');
jQuery.get("http://127.0.0.1/auth_system_1/user_activity/delete_user_ban", { ban_id : ban_id, num : num }, function(data) {
jQuery("#ban_list").append(data);
}, "json");
});
My delete_user_ban function
function delete_user_ban()
{
$user_id = $this->session->userdata('user_id');
$ban_id = $this->input->post('ban_id');
$current_page = (int)$this->input->post('num');
//$this->activity_model->delete_user_ban($ban_id);
$per_page = 2;
$data['ban_list'] = $this->user_activity_lib->user_ban_list($user_id, $current_page, $per_page);
$this->load->view('front_end/ajax_delete_ban', $data);
}
and I want to return it here
<!--begin ban list-->
<div id="ban_list">
<?php foreach($ban_list as $value): ?>
<div class="comment-box small-comment" id="info-ban-1">
<div class="photo-box">
<img src="<?=$value['user_image'];?>" alt="" class="photo rounded"/>
<a href="#" title="" class="corner rounded"></a>
</div>
<div class="comment rounded">
<div class="bg-tl"></div>
<div class="avatars">
<a href="#" title=""><?=$value['user'];?></a><span>blocked</span><a href="<?=base_url() . $value['ban_user'];?>" title=""><img src="<?=$value['user_ban_image'];?>" alt=""/><?=$value['ban_user'];?></a>
<a href="[removed];" title="Unblock" class="unblock" id="<?=$value['ban_id'];?>">unblock</a>
</div>
</div>
<div class="both"></div>
</div>
<?php endforeach; ?>
</div>
<!--end ban list-->
<?=$pagination;?>
</div>
What can I say, everything works good EXCEPT data not returned to .
If I delete this line in function :
$this->load->view(‘front_end/ajax_delete_ban’, $data);
and add echo ‘1’;
it return where I want ‘1’ but content from here $this->load->view(‘front_end/ajax_delete_ban’, $data); do not return to this div ? Why ?
I have watched response and html what return and here is html lines returning from view (no errors) but do not appear in JQuery(”#ban_list”).append(data);
My .get works good but only return one word, also looking response and html in firebug it show returned lines but do not add it to div?
I have made some test :
echo '1111';
return OK!
echo '1111 2222';
do not return ?
How to return more then one word and where is my mistake ?
Upvotes: 0
Views: 1234
Reputation: 20492
Try this instead:
jQuery("#ban_list").append($('<div></div>').html(data));
Upvotes: 0
Reputation: 7408
You're mixing get's and post's, no?
Either change your jQuery to $.post()
Or change your PHP to $this->input->get();
You're also using 'json' in your $.get() call, but returning HTML.
You should json_encode your view.
You can hand a boolean third parameter to $this->load->view()
that will return the HTML in the view to a string.
$myHTML = $this->load->view('front_end/ajax_delete_ban', $data, true);
echo json_encode(array("html" => $myHTML));
Then, in your jQuery callback function, you can retreive the html using data.html
Upvotes: 1