codeigniter问题中的Ajax [英] Ajax in codeigniter issue

查看:81
本文介绍了codeigniter问题中的Ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有codeigniter的ajax刷新/重新加载页面。

代码工作正常但是它正在加载我的整个页面[view]而我只想加载表格或者一些特定容器但使用相同的视图。我检查了很多问题,但没找到我想要的,请检查问题而不是投票。它有什么问题?有人可以看一下。



我尝试了什么:



I am trying to refresh / reload the page using ajax with codeigniter.
The code is working fine but it is loading my whole page [view] and i want to only load the table or some specific container but using the same view. I check a lot of question but did not find what i want, Please check the question instead of down voting. What is wrong in it? can someone please look at it.

What I have tried:

View:

      <pre lang="PHP"><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Insert | SP</title>
      <script src="<?php echo base_url(); ?>bootstrap/js/jquery-2.1.1.min.js"></script>

<script>
        $(document).ready(function(){

            function loadNowPlaying(){
      $(this).load('<?php echo base_url().'Store/student' ;?>');
    }
    setInterval(function(){loadNowPlaying()}, 5000);
        });


        </script>

 </head>
    <body>
        <form action="<?php echo base_url();?>Store/add" method="post">
            <input type="text" name="name" id="name"><br>
            <input type="text" name="mail" id="mail"><br>
            <input type="password" name="pass" id="pass"><br>
            <input type="submit" name="submit" id="submit" value="Insert">
        </form>


        <table id="studata">
           <?php foreach ($students as $student):?>
            <tr>
               <th>Name</th>
               <th>Email</th>
               <th>Password</th>
            </tr>
               <tr>
                <td><?php echo $student->Name;?></td>
                <td><?php echo $student->Email;?></td>
                <td><?php echo $student->Password;?></td>
            </tr>
            <?php endforeach;?>
        </table>
    </body>
    </html>





我的控制器代码:









My Controller code:



public function student()
    {
        $data["students"] = $this->sp->getstudent();
        $this->load->view('student',$data);
    }





我的型号:







My Model:


public function getstudent()
    {
         $this->db->select('*');
        $this->db->from('ex_sp');
        $query = $this->db->get();
        return $query->result();
    }

推荐答案

(document).ready(function(){

function loadNowPlaying( ){
(document).ready(function(){ function loadNowPlaying(){


(this).load('<?php echo base_url()。'store / student';?>');
}
setInterval(function(){loadNowPlaying()},5000);
});


< / script>

< / head>
< body>
< form action =<?php echo base_url();?>存储/添加method =post>
< input type =textname =nameid =name>< br>
< input type =textname =mailid =mail>< br>
< input type =passwordname =passid =pass>< br>
< input type =submitname =submitid =submitvalue =Insert>
< / form>


< table id =studata>
<?php foreach(
(this).load('<?php echo base_url().'Store/student' ;?>'); } setInterval(function(){loadNowPlaying()}, 5000); }); </script> </head> <body> <form action="<?php echo base_url();?>Store/add" method="post"> <input type="text" name="name" id="name"><br> <input type="text" name="mail" id="mail"><br> <input type="password" name="pass" id="pass"><br> <input type="submit" name="submit" id="submit" value="Insert"> </form> <table id="studata"> <?php foreach (


学生


这篇关于codeigniter问题中的Ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆