单击按钮时自动更新表格

时间:2014-02-04 12:40:18

标签: javascript php mysql

我在页面中有一个表格。我想连续更新/重新加载表格点击按钮 每5秒

该表从模型中运行的查询中获取值,我不希望将重复值再次放入表中。

当我点击另一个停止按钮时,我也想停止重新加载

我该怎么办?谢谢!

2 个答案:

答案 0 :(得分:0)

单击第一个按钮设置间隔功能时,将执行更新脚本。然后点击其他按钮将清除此间隔。

// Click on first button
var flag = setInterval(func, 5000);

// Click on second button   
clearInterval(flag);

其中func是您的更新功能

答案 1 :(得分:0)

尽可能尝试。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using bhanu1.Models;
namespace bhanu1.Controllers
{
    public class ranuController : Controller
    {
        //
        // GET: /ranu/
        private personEntities1 per = new personEntities1();
        public ActionResult Index()
        {
            return View(per.sandeep1.ToList());
        }
        //
        // GET: /ranu/Details/5
        public ActionResult Details(int id)
        {
            return View();
        }
        //
        // GET: /ranu/Create
        public ActionResult Create()
        {
            return View();
        } 
        //
        // POST: /ranu/Create
        [HttpPost]
        public ActionResult Create([Bind(Exclude = "Id")]sandeep1 san)
        {
            try
            {
                // TODO: Add insert logic here
                per.AddTosandeep1(san);
                per.SaveChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        //
        // GET: /ranu/Edit/5
        public ActionResult Edit(int id)
        {
            return View();
        }
        //
        // POST: /ranu/Edit/5
        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        //
        // GET: /ranu/Delete/5
        public ActionResult Delete(int id)
        {
            return View();
        }
        //
        // POST: /ranu/Delete/5
        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                return RedirectToAction("Index");
            }
            catch
           {
                return View();
            }
        }
    }
}
相关问题