Reputation: 7563
I'm trying to call a page on my server every second, only if the current page the user is on is a Create
page or an Edit
page. But this code does not work:
function sessionRefresh(){
var remoteURL = '/path/to/file';
$.get(remoteURL, function(data){
setTimeout('sessionRefresh()',1000);
});
}
if(window.location.href.indexOf("/create" != -1) || window.location.href.indexOf("/edit" != -1)) {
setTimeout('sessionRefresh()',1000);
}
The sessionRefresh() function is running on all pages. But I only want it to run if the URL has /create
or /edit
in it. Just to note, I'm not going to get this file every second on the production server. Its just for testing.
How can I rewrite this so that the function is only called on those create and edit pages?
Upvotes: 0
Views: 1472
Reputation: 526
Replace
if(window.location.href.indexOf("/create" != -1) || window.location.href.indexOf("/edit" != -1)) {
setTimeout('sessionRefresh()',1000);
}
with
if(window.location.href.indexOf("/create") != -1 || window.location.href.indexOf("/edit") != -1) { setTimeout('sessionRefresh()',1000); }
Upvotes: -1
Reputation: 5323
You made a copy-paste typo, try
if(window.location.href.indexOf("/create") != -1 || window.location.href.indexOf("/edit") != -1) {
instead of
if(window.location.href.indexOf("/create" != -1) || window.location.href.indexOf("/edit" != -1)) {
Upvotes: 2