Javascript 单击按钮自动更新表格
我有一张一页的桌子。我想每隔5秒点击按钮持续更新/重新加载表格 该表从模型中运行的查询中获取值,我不希望将重复的值再次放入表中 我还想在单击另一个按钮(即停止按钮)时停止重新加载表Javascript 单击按钮自动更新表格,javascript,php,mysql,Javascript,Php,Mysql,我有一张一页的桌子。我想每隔5秒点击按钮持续更新/重新加载表格 该表从模型中运行的查询中获取值,我不希望将重复的值再次放入表中 我还想在单击另一个按钮(即停止按钮)时停止重新加载表 我怎么做?谢谢 当您单击第一个按钮时,设置间隔函数将执行您的更新脚本。单击“其他”按钮将清除此间隔 // Click on first button var flag = setInterval(func, 5000); // Click on second button clearInterval(flag
我怎么做?谢谢 当您单击第一个按钮时,设置间隔函数将执行您的更新脚本。单击“其他”按钮将清除此间隔
// Click on first button
var flag = setInterval(func, 5000);
// Click on second button
clearInterval(flag);
其中func是更新函数如果可能的话,尝试一下
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();
}
}
}
}
为什么要每5秒更新一次表?我建议您使用输入的onkeyup/onchange绑定更新。这样,向服务器发出的请求就会少很多,这不是一个超时函数,若我想运行一个查询并用一个按钮在表中重新加载,我应该怎么做;query是运行查询和更新表的函数,所以我会在query函数中编写mymysql语句。所以你想每5秒重新加载整个页面?因为您在服务器上处理表页?