xoops forums

Zap_English

Quite a regular
Posted on: 8/21 0:05
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 343
Since: 2016/5/24
#1

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

blindman

Not too shy to talk
Posted on: 8/21 13:41
blindman
blindman (Show more)
Not too shy to talk
Posts: 112
Since: 2005/6/26
#2

Re: A tricky question about

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.

bitcero

Quite a regular
Posted on: 8/27 16:40
bitcero
bitcero (Show more)
Quite a regular
Posts: 318
Since: 2005/11/26
#3

Re: A tricky question about

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.