views:

65

answers:

2

Hi all, I am developing one application using PHP, jQuery, Javascript in CodeIgniter.

I included script.js file in view file. The problem is the view file is continuously loading again and again with in the result div called "new".

Please help me. Below are the files and code.

View file

<?php $this->load->view('header'); ?>
 <script type="text/javascript" src="<?php echo base_url();?>js/script.js"></script>
<div id="content"> 
<div id="news">
</div>
</div>

script.js has the following code:

$.post('news/getnews', function(data) {

  $('#news').append(data);
});

In controller,

function getnews()
{

  echo some data.
}

It only loading the result again and again when I use Post, ajax etc methods. i.e, when I try to get data from controller and append to view using Javascript.

Thanks, Raj

A: 

Please try

$('#news').html(data);
Mike
Thanks for your reply. I tried but no use. The view page including header is loading in div #news again and again continuously.
Raj
have you included js function in the $(document).ready(function() {});?
Mike
I wrote the js function in $(document).ready(function() {}); Thanks
Raj
I just echoed the returned data from controller to the js post function using alert(data); But the "data" has entire view page html code instead of what I am returning.
Raj
I got it. Actually the controller path is wrong. $.post('news/getnews', function(data) { $('#news').append(data);}); here I replaced the post url "news/getnews" with getnews. It works.
Raj
A: 

Uh... is your view file named getnews? If so then you it will continuously be calling itself.

Gutzofter
No, Its name is home_view.php
Raj
Do I have to change any configuration settings etc...?
Raj