I have one input and script to reload table in my page. In the input if I insert 1000 I want to reload page every second, without clicking any buttons.
This is what I tried:
<input id="txtRefresh" />
<script>
document.redy(function () {
$('tblRefresh').load();
setInterval(function () {
$('#tblRefresh').load();
}, 'txtRefresh');
});
</script>
Its cshtml
razor page.
What I want to do is to insert the value of seconds in the input
andrefresh the page based of the of the inserted value, without submiting any data.
Is it possible to do this? Any suggestions?
Thanks in advance!
UPDATE
I inserted this script:
<script>
document.ready(function () {
$('#refreshDIV').load('url/url/url');
setInterval(function () {
$('#refreshDIV').load('url/url/url');
}, $('#txtRefresh').val());
});
</script>
But it gaves me error!
refreshDIV
is a div that I want to refresh
txtRefresh
is the input from I insert the seconds
you can try this:
$(document).ready(function(){
var timeout = $("#txtRefresh").val();
setTimeout(timeout, function() { location.href=""; });
});
but each time you will reload the page you will lose, the input. You could send it through querystring like this:
location.href="?timeout="+timeout
and populate the input server side
This is just a string:
'txtRefresh'
If you want to get the value of that element , it would be more like this:
$('#txtRefresh').val()
You also have a typo in document.ready
and in your first #tblRefresh
selector (missing the #
), and you aren't supplying .load()
with the URL you want to load . All together you appear to be trying to do this:
$(document).ready(function () {
$('#tblRefresh').load('/some/url');
setInterval(function () {
$('#tblRefresh').load('/some/url');
}, $('#txtRefresh').val());
});
A couple things to note:
The value /some/url
is of course a placeholder in this sample code. Whatever URL you want to use in your application is up to you.
Calling .load()
will place the entire response of that URL into the target element. If you want only a subset of that response, you can add selectors to .load()
. For example:
$('#tblRefresh').load('/some/url #someElement');
This would tell .load()
to grab all the content from /some/url
and then only select from it the content of #someElement
to place in #tblRefresh
. The performance could still potentially be slow as all of the content from the URL is still downloaded. To address performance or for finer control over data, consider returning JSON data from the server and using .ajax()
to fetch that data instead of using .load()
to reload all of the HTML (when only the data has changed).
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.