1
Zap_English
A tricky question about

XOOPS Version XOOPS 2.5.9-Beta2
PHP Version 7.0.21
mySQL Version 5.5.52-MariaDB
Server API cgi-fcgi
OS Linux

I want to install some java script and it says to place the code in the tags

This is the code

$(document).ready( function() {
  $(
'#auto').load('display.php');
  
refresh();
});

function 
refresh() {
  
setTimeout( function() {
    $(
'#auto').load('display.php');
    
refresh();
  }, 
1000);
}


I also have to insert in the tag

<script type="text/java script" src="http://code.jquery.com/jquery-1.7.2.min.js">script>


And then in a block on my home page i will put

<div id="auto">div>


This will put a "now playing" block on the home page showing album art, song name, artist, album name and release date

The question is, where do I put the code for the body tag? index.php or another page? I don't want to screw up any existing code so I need some advice where to put that code

2
blindman
Re: A tricky question about
  • 2017/8/21 13:41

  • blindman

  • Not too shy to talk

  • Posts: 119

  • Since: 2005/6/26


edited:
You could use jQuery ajax to load something in a block.
You can send some variables by POST or GET and receive html code. Or set -> dataType: 'json' and you can receive structured data as array.

javascript part:
$(document).ready( function() { 
    
refreshMyDisplay(1);
    function 
refreshMyDisplay(myCount) {
        if(
myCount==1){
            var 
myTimer 1000;
        }
        else{
            var 
myTimer 10000;
        }
          
setTimeout( function() {
            $.
ajax({
                
url'completePathTo/display.php',
                
dataType'html',
                
data:     {
                    
var_one'val_one'
                    
var_two'val_two'
                },
                
type:     "POST",    
                
beforeSend: function() {
                    
// add a spinner by adding a class
                    
$('#auto').addClass("ajaxLoader");
                },
                
error:     function() {
                    
// display some feedback
                
},
                
success: function(e) {
                    $(
'#auto').removeClass("ajaxLoader"); // remove spinner
                    
$('#auto').html(e);
                }
            });
            
myCount myCount 1;
          }, 
myTimer);
        
refreshMyDisplay(myCount);
    }
});

html part:
<div id="auto">div>


Javascript works with miliseconds, so 1000=1 sec.

3
bitcero
Re: A tricky question about
  • 2017/8/27 16:40

  • bitcero

  • Quite a regular

  • Posts: 318

  • Since: 2005/11/26


If I understand your question.... You must add a new custom block with "content type". Put in this block your code:
<div id="auto">div>
For jquery script tag you must add this to your theme, and in the home page template. Also add to the same template your custom script that loads display.php file. Alternatively you can put your script directly in the custom block content. Don't forget to enable the new block only for homepage.

Login

Who's Online

426 user(s) are online (299 user(s) are browsing Support Forums)


Members: 0


Guests: 426


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits