简体   繁体   中英

Ajax internal page load

How can I load a new page in my particular div using ajax in CodeIgniter framework?

I have written the function and it works with plain php.

Example:

href="abc1.php" onclick="makerequest('abc1.php','div_name');return false;"> Page 1

href="abc2.php" onclick="makerequest('abc2.php','div_name');return false;"> Page 2 

Note: ajax makerequest function is working properly.

My problem is: how can I pass my view file in replace of abc1.php/abc2.php in CodeIgniter framework? Those files are located on my base_url/view/ . I try to retrieve the filename using controller but it isn't working.

see my code below:

..........................link.............
 href="<?=base_url()?>main_controller/newPage1.html" onclick="makerequest('<?=base_url()?>main_controller/newPage1.html','upper_middle');return false;">abc1 

href="<?=base_url()?>main_controller/newPage2.html" onclick="makerequest('<?=base_url()?>main_controller/newPage2.html','upper_middle');return false;">abc2 
.................................
...........controller code...

function newPage1()
{
  return $this->load->view('abc1.php');    
}

How can I do that? Or is there any other way to do it easily?

You could use codeignator with JQuery . Using JQuery, you load a url into an element, which could be a div as follows $('#element_id').load(url).

Note that you can replace #element_id with any valid css selector, or even use XPath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM