如何在x秒后自动重新加载页面并重新提交表单数据

时间:2016-11-01 20:52:04

标签: javascript jquery html twitter-bootstrap

我有2个HTML页面:一个询问用户有关某个主题的输入,另一个用于从与该主题相关的Twitter Streaming API中提取Twitter数据。然而,这些信息不断变化。当我手动刷新时,弹出窗口通知我我想要"确认数据重新提交"当我点击"继续"时,它会给我新的信息。我想在我的代码中自动执行此操作,并且每10秒执行一次。

我的HTML页面是与Flask一起创建的,并使用Twitter Bootstrap CSS和JS文件。我尝试使用func registerForKeyboardNotifications(){ NotificationCenter.default.addObserver(self, selector: #selector(keyboardWasShown(notification:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillBeHidden(notification:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil) } func deregisterFromKeyboardNotifications(){ NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil) NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil) } func keyboardWasShown(notification: NSNotification){ self.scrollView.isScrollEnabled = true var info = notification.userInfo! let keyboardSize = (info[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size let contentInsets : UIEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize!.height, 0.0) self.scrollView.contentInset = contentInsets self.scrollView.scrollIndicatorInsets = contentInsets var aRect : CGRect = self.view.frame aRect.size.height -= keyboardSize!.height if let activeField = self.activeField { if (!aRect.contains(activeField.frame.origin)){ self.scrollView.scrollRectToVisible(activeField.frame, animated: true) } } } func keyboardWillBeHidden(notification: NSNotification){ var info = notification.userInfo! let keyboardSize = (info[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size let contentInsets : UIEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, -keyboardSize!.height, 0.0) self.scrollView.contentInset = contentInsets self.scrollView.scrollIndicatorInsets = contentInsets self.view.endEditing(true) self.scrollView.isScrollEnabled = false } func textFieldDidBeginEditing(_ textField: UITextField){ activeField = textField } func textFieldDidEndEditing(_ textField: UITextField){ activeField = nil } 方式,虽然它会自动刷新页面,但它不保留在上一页提交的表单数据。

这样的事情是不可能的吗?

3 个答案:

答案 0 :(得分:2)

我假设您有一个提交此表单的按钮。您是否考虑过订阅onClick事件?您可以创建一个回调函数,并在其中从窗口全局对象中调用location.reload();

答案 1 :(得分:2)

您可以使用:

location.reload();

setInterval();

答案 2 :(得分:2)

要设置时间间隔,您可以使用此window.setInterval(function, milliseconds)以获取文档

  

http://www.w3schools.com/js/js_timing.asp