catherinePHP Posted April 25, 2013 Share Posted April 25, 2013 I don't know what's wrong with my script, when I login into a page it redirects me to the admin page normally but the admin page keeps refreshing! I've located the problem which is in my javascript but I don't know what's wrong with it. Here is the javascript code: $(document).ready(function() { (function($){ $.fn.avu = function() { $.post('backend/build_table.php', { 'session_id' : sessid }, function(data) { // login check try { JSON.parse(data); } catch (e) { location.href = './index.php'; return; } data = jQuery.parseJSON(data); var tbl = ""; $.each(data, function(id, row) { $('.tooltip').hide(); $("tbody tr").remove(); var tbl_row = ""; var hash; var name; $.each(this, function(k , v) { if(k=='hash'){hash=v;} if(k=='name'){name=v;} if(k=='filepath' || k=='results'){return;} else if(k=='size'){ tbl_row += '<td class="'+k+'">'+bytesToSize(v)+"</td>\n"; } else if(k=='scanned') { // set status if(v=='0') { v = 'In queue'; } else if(v=='1' && row['results'] == null) { v = 'Clean'; } else if(v=='1' && row['results'] != null) { v=''; var results = jQuery.parseJSON( row['results']); v+='<ul>'; $.each(results, function(kr,r) { v+='<li class="small"><span class="tt" title="Scanned with: '+r.scanner+'">'+r.result+ '</span></li>' + "\n"; }); v+='<ul>'; } tbl_row += '<td class="'+k+'">'+v+"</td>\n"; } else{ tbl_row += '<td class="'+k+'">'+v+"</td>\n"; } }) // add extra row var durl = 'download/'+hash+'/'+name; tbl_row += '<td><a href="'+durl+'" target="blank"><img src="assets/img/download.png" class="tt bdown" title="Download file" /></a>'+ '<img src="assets/img/delete.png" class="tt bdel"title="Remove file" /></td>'; tbl += '<tr id="'+row['id']+'">'+tbl_row+"</tr>\n"; }); // build $("tbody").html(tbl); $('.tt').tooltip({'delay':4}); // remove file $(".bdel").click(function() { var id= $(this).parent().parent().attr('id'); $.post("backend/delete_file.php", { id: id, 'session_id' : sessid }, function(data) { $('tr[id="'+id+'"]').remove(); $('.tooltip').hide(); //rebuild setTimeout(function() { $('tbody').avu(); }, 2000); }); }); }); }; })(jQuery); // build and refresh table $('tbody').avu(); setInterval(function() { $('tbody').avu(); }, 20000); /** * Convert number of bytes into human readable format * * @param integer bytes Number of bytes to convert * @return string */ function bytesToSize(bytes) { var sizes =['Bytes','KB','MB','GB','TB']; if(bytes==0) return 'n/a'; var i=parseInt(Math.floor(Math.log(bytes)/Math.log(1024))); return Math.round(bytes/Math.pow(1024,i),2)+' '+sizes[i]; } }); What causes the page to refresh every 2 seconds? and how can I fix this? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/277298-problem-script-causes-the-page-to-automatically-refresh-problem/ Share on other sites More sharing options...
yomanny Posted April 26, 2013 Share Posted April 26, 2013 (edited) Perhaps it's failing at this line, and therefore redirects you to ./index.php ? // login check try { JSON.parse(data); } catch (e) { location.href = './index.php'; return; } - W Edited April 26, 2013 by yomanny Quote Link to comment https://forums.phpfreaks.com/topic/277298-problem-script-causes-the-page-to-automatically-refresh-problem/#findComment-1426705 Share on other sites More sharing options...
catherinePHP Posted April 26, 2013 Author Share Posted April 26, 2013 Perhaps it's failing at this line, and therefore redirects you to ./index.php ? // login check try { JSON.parse(data); } catch (e) { location.href = './index.php'; return; } - W Thanks for the help, fixed it now everything works properly Quote Link to comment https://forums.phpfreaks.com/topic/277298-problem-script-causes-the-page-to-automatically-refresh-problem/#findComment-1426711 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.