Jump to content

can someone explain what this code trying to do??


Recommended Posts

	var ajaxRequest4;  

	// The variable that makes Ajax possible!		

	try{		// Opera 8.0+, Firefox, Safari		

	ajaxRequest4 = new XMLHttpRequest();	} catch (e){		

	// Internet Explorer Browsers		

	try{			

	ajaxRequest4 = new ActiveXObject("Msxml2.XMLHTTP");		} catch (e) {			try{				ajaxRequest4 = new ActiveXObject("Microsoft.XMLHTTP");			} catch (e){				

	// Something went wrong				

	alert("Your browser broke!");				return false;			}		}	}	

	// ********** DATA 04 ********** VIDEO	

	// Create a function that will receive data sent from the server	

	ajaxRequest4.onreadystatechange = function(){		

	if(ajaxRequest4.readyState == 4){			

	var ajaxDisplay4 = document.getElementById('ajaxDivVideo');			

	ajaxDisplay4.innerHTML = ajaxRequest4.responseText;			

	loadNplay(document.getElementById('myvideourladdr').value);		}	}	

	// var fid = document.getElementById('fid').value;	

	var queryString4 = "?fid=" + fid;	ajaxRequest4.open("GET", "../jrp/readpropertyvideo.php" + queryString4, true);	ajaxRequest4.send(null); 	

looks like it is establishing an asynchronous connection to the server using AJAX method.. sends data to the given url, and places the response into the element with id = ajaxDivVideo.. also applies a custom function..

Thank you one more question this might be a mix of php the ur from that ajax is readpropertyvideo.php now on this page i have the above script which works fine my question is? is there a way on that same ajax script that i can get it to send to 2 different url like at moment it is going to readpropertyvideo.php how can i get so that it also goes to indextest.php?

<?php	include("../../includes/config.php");

mysql_connect($db_address, $db_username, $db_password);	
mysql_select_db($db_name) or die(mysql_error());	
$fid = $_GET['fid'];	
$fid = mysql_real_escape_string($fid);	
$query4 = "SELECT * FROM films WHERE (film_id = '$fid')";
$qry_result4 = mysql_query($query4) or die(mysql_error());	
while($row = mysql_fetch_array($qry_result4))	
{		
$myfilmurlstr = "http://www.onfilm.biz/streaming/home/$row[film_client]/$row[film_client_office]/$row[film_filename].mp4";		$display_string4 .= "<input name='myvideourladdr' type='hidden' id='myvideourladdr' value='$myfilmurlstr' size='72'>";	}	
mysql_close(); 
//EDIT 290510	
echo $display_string4;?>

to my knowledge, you cannot have two open() methods in one ajax request, could be mistaken.. I believe that you would have to create another AJAX call in the same function to get your desired functionality..

 

also, I recommend using jquery's AJAX API instead of standard js

Do you mean doing something like duplicat this part but with a differenr url instead of jrp/readpropertyvideo.php one with bellway/indextest.php

ajaxRequest4.onreadystatechange = function(){

 

if(ajaxRequest4.readyState == 4){

var ajaxDisplay4 = document.getElementById('ajaxDivVideo');

ajaxDisplay4.innerHTML = ajaxRequest4.responseText;

loadNplay(document.getElementById('myvideourladdr').value); } }

// var fid = document.getElementById('fid').value;

var queryString4 = "?fid=" + fid; ajaxRequest4.open("GET", "../bellway/indextest.php" + queryString4, true); ajaxRequest4.send(null);

 

 

so the overall code would be like??

var ajaxRequest4; 

 

// The variable that makes Ajax possible!

 

try{ // Opera 8.0+, Firefox, Safari

 

ajaxRequest4 = new XMLHttpRequest(); } catch (e){

 

// Internet Explorer Browsers

 

try{

 

ajaxRequest4 = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest4 = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){

 

// Something went wrong

 

alert("Your browser broke!"); return false; } } }

 

// ********** DATA 04 ********** VIDEO

 

// Create a function that will receive data sent from the server

 

ajaxRequest4.onreadystatechange = function(){

 

if(ajaxRequest4.readyState == 4){

 

var ajaxDisplay4 = document.getElementById('ajaxDivVideo');

 

ajaxDisplay4.innerHTML = ajaxRequest4.responseText;

 

loadNplay(document.getElementById('myvideourladdr').value); } }

 

// var fid = document.getElementById('fid').value;

 

var queryString4 = "?fid=" + fid; ajaxRequest4.open("GET", "../jrp/readpropertyvideo.php" + queryString4, true); ajaxRequest4.send(null);

 

 

// SEND TO SECOND URL

 

 

 

ajaxRequest4.onreadystatechange = function(){

 

if(ajaxRequest4.readyState == 4){

 

var ajaxDisplay4 = document.getElementById('ajaxDivVideo');

 

ajaxDisplay4.innerHTML = ajaxRequest4.responseText;

 

loadNplay(document.getElementById('myvideourladdr').value); } }

 

// var fid = document.getElementById('fid').value;

 

var queryString4 = "?fid=" + fid; ajaxRequest4.open("GET", "../bellway/indextest.php" + queryString4, true); ajaxRequest4.send(null);

You might be right but i don't think i've actually lay out my problem propelly

this my issue

I have a the following site

http://www.estateagentsonfilm.co.uk/tv/bellway/indextest.php#

the site uses a jwplayer and php to load the video into the player this how the php load the video into the player the full script bellow but this the line that loads the

$efilm="http://www.onfilm.biz/streaming/home/".$client."/".$client.".mp4"; and on the player i'll have the <?php echo $efilm; ?>

Now this is the first movie the player picks up but what i am trying to figure out is when you click a different propriety from the link above it plays a different video what i wanted to know how is that that video gest load into the player when i only have the first video onto the player which is <?php echo $efilm; ?>

i do have other files but they written in ajax which which i don't really understand if anyone here understand ajax i can send all three files to have a look if possible

thanks in advance

 

?php
$playme = "true";
?>

<?php	//
$playme=1;	if($efilm=="")
      {
	 $efilm="http://www.onfilm.biz/streaming/home/".$client."/".$client.".mp4";	
  }
   else
  {		// nothing	
      }
?>

include("../../includes/config.php");	    	//connect to DB	
$connectionci = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT.");
$dbci = @mysql_select_db($db_name, $connectionci) or die("Couldn't select DATABASE.");		//SELECT All based on current cookie Information	
$queryci="SELECT * FROM clients WHERE (client_company = '$client')";	
$resultci = mysql_query($queryci) or die("Couldn't execute QUERY.");	
        while ($rowci = mysql_fetch_array($resultci))
{
$client_name			= $rowci[client_company_name];    	      
    $client_addr_01 		= $rowci[client_address01];
$client_addr_02 		= $rowci[client_address02];	
    $client_addr_city 		= $rowci[client_city];
$client_addr_county 	= $rowci[client_county];			
    $client_addr_postcode 	= $rowci[client_postcode];
$client_addr_telephone 	= $rowci[client_telephone];		
    $client_addr_email 		= $rowci[client_email];
$client_url 	        = $rowci[client_url];
}
	mysql_close($connectionci);
?>

<script type="text/javascript" src="../jwplayer/jwplayer.js"></script>
<script type="text/javascript">
	jwplayer("mediaplayer").setup({
    'flashplayer': '../jwplayer/player.swf',
    'id': 'playerID',
    'width': '640',
    'height': '360',
 'file': '<?php echo $efilm; ?>',
	'skin': '../jwplayer/glow.zip',
'dock': 'false',
'viral.oncomplete': 'false',
'hd.state': 'false',
'viral.allowmenu': 'false',
     autostart: true,
     'plugins': {
       'hd-1': {
	           file: '<?php echo $stream="http://www.onfilm.biz/streaming/home/$row[film_client]/$row[film_client_office]/$row[film_filename].mp4"; ?>'
	   }
    }

  }); 
      
var player = null;		      
function playerReady(obj)	      
{	        
	player = document.getElementsByName(obj.id)[0];
}
   
function loadNplay(file)	      
{	        
   		if(player!=null){
		player.sendEvent('LOAD', {file:file, type:'video'});	        
   			player.sendEvent('PLAY', 'true');	      
	}
}
	      	      
function playerStart(file)	      
{	      	
	player.sendEvent('PLAY',true);	      
}	      			
function playerStop(file)	      
{	      	
	player.sendEvent('STOP');	      
}
function playerPause(file)	      
{	      	
	player.sendEvent('PLAY',false);
}
   	
</script>
<script>	
//call after page loaded		
window.onload=function(){
ajaxFunction1();
setTimeout("createPlayer()",2000);
}
</script>


Thanks for the help!

why is that when i try to do same query on different pages one queries from the database but the other one doesnt retrieve the data from the database

 

readopropertyvideo.php script

<?php	include("../../includes/config.php");

mysql_connect($db_address, $db_username, $db_password);	
mysql_select_db($db_name) or die(mysql_error());	
$fid = $_GET['fid'];	
$fid = mysql_real_escape_string($fid);	
$query4 = "SELECT * FROM films WHERE (film_id = '{$fid}')";
$qry_result4 = mysql_query($query4) or die(mysql_error());	
while($row = mysql_fetch_array($qry_result4))	
{		
$myfilmurlstr = "http://www.onfilm.biz/streaming/home/$row[film]/$row[client_office]/$row[filename].mp4";
$display_string4 .= "<input name='myvideourladdr' type='hidden' id='myvideourladdr' value='$myfilmurlstr' size='72'>";	}	
mysql_close(); 
//EDIT 290510	
echo $display_string4;?>

result correct

readopropertyvideo.php url shows correct

http://www.onfilm.biz/streaming/home/film/clientoffice/filename.mp4

 

now i tried a similiar script on the indextest.php

but it doesnt query from the database its shows

http://www.onfilm.biz/streaming/home///.mp4

<?php	include("../../includes/config.php");

mysql_connect($db_address, $db_username, $db_password);	
mysql_select_db($db_name) or die(mysql_error());	
$fid = $_GET['fid'];	
$fid = mysql_real_escape_string($fid);	
$query4 = "SELECT * FROM films WHERE (film_id = '{$fid}')";
$qry_result4 = mysql_query($query4) or die(mysql_error());	
while($row = mysql_fetch_array($qry_result4))	
{		
$myfilmurlstr = "http://www.onfilm.biz/streaming/home/$row[film]/$row[client_office]/$row[filename].mp4";
$display_string4 .= "<input name='myvideourladdr' type='hidden' id='myvideourladdr' value='$myfilmurlstr' size='72'>";	}	
mysql_close(); 
//EDIT 290510	
echo $display_string4;?>

1. no errors triggered by the mysql_query..?

2. the parenthesis around the WHERE clause statement are not needed..

3. try outputting $qry_result4 to make sure your query is what you expect..

4. you can also use mysql_num_rows() to see how many rows your query is grabbing..

5.  place quotes around your indices.. good practice.. $row['film'] not $row[film]

No i get no error you can see the outcome on the link bellow all of those property links are from that same query which works fine but the query comes from the page file readpropertyvideo.php

http://www.estateagentsonfilm.co.uk/tv/bellway/indextest.php

but when i try the same query by putting the exact same query on the index.php the data are not retrieved.

 

i do suspect the reason why the script will only work on the readpropertyvideo.php is because on this ajax code bellow thers a GET statement that says to readpropertyvideo.php, but i tried to change to indextest.php but still doesnt run? the code only seems to run with the readpropertyvideo.php. I can then grab the url link from when the user clicks and store on another variable since the way i am trying to do is not queyring??

 

// Create a function that will receive data sent from the server	

	ajaxRequest4.onreadystatechange = function(){		

	if(ajaxRequest4.readyState == 4){			

	var ajaxDisplay4 = document.getElementById('ajaxDivVideo');			

	ajaxDisplay4.innerHTML = ajaxRequest4.responseText;			

	loadNplay(document.getElementById('myvideourladdr').value);		}	}	

	// var fid = document.getElementById('fid').value;	

	var queryString4 = "?fid=" + fid;	ajaxRequest4.open("GET", "../jrp/readpropertyvideo.php" + queryString4, true);	ajaxRequest4.send(null); 

i dont really understand about ajax but ok this how i am thinking creating 2 ajax function do i just change the url but keep the same fuction exacly how they are??

function one to the url readpropertyvideo

	var ajaxRequest4;  
	// The variable that makes Ajax possible!		
	try{		// Opera 8.0+, Firefox, Safari		
	ajaxRequest4 = new XMLHttpRequest();	} catch (e){		
	// Internet Explorer Browsers		
	try{			
	ajaxRequest4 = new ActiveXObject("Msxml2.XMLHTTP");		} catch (e) {			try{				ajaxRequest4 = new ActiveXObject("Microsoft.XMLHTTP");			} catch (e){				
	// Something went wrong				
	alert("Your browser broke!");				return false;			}		}	}	
	// ********** DATA 04 ********** VIDEO	
	// Create a function that will receive data sent from the server	
	ajaxRequest4.onreadystatechange = function(){		
	if(ajaxRequest4.readyState == 4){			
	var ajaxDisplay4 = document.getElementById('ajaxDivVideo');			
	ajaxDisplay4.innerHTML = ajaxRequest4.responseText;			
	loadNplay(document.getElementById('myvideourladdr').value);		}	}	
	// var fid = document.getElementById('fid').value;	
	var queryString4 = "?fid=" + fid;	ajaxRequest4.open("GET", "../jrp/readpropertyvideo.php" + queryString4, true);	ajaxRequest4.send(null); 	

 

Jax function 2

	var ajaxRequest4;  

	// The variable that makes Ajax possible!		

	try{		// Opera 8.0+, Firefox, Safari		

	ajaxRequest4 = new XMLHttpRequest();	} catch (e){		

	// Internet Explorer Browsers		

	try{			

	ajaxRequest4 = new ActiveXObject("Msxml2.XMLHTTP");		} catch (e) {			try{				ajaxRequest4 = new ActiveXObject("Microsoft.XMLHTTP");			} catch (e){				

	// Something went wrong				

	alert("Your browser broke!");				return false;			}		}	}	

	// ********** DATA 04 ********** VIDEO	

	// Create a function that will receive data sent from the server	

	ajaxRequest4.onreadystatechange = function(){		

	if(ajaxRequest4.readyState == 4){			

	var ajaxDisplay4 = document.getElementById('ajaxDivVideo');			

	ajaxDisplay4.innerHTML = ajaxRequest4.responseText;			

	loadNplay(document.getElementById('myvideourladdr').value);		}	}	

	// var fid = document.getElementById('fid').value;	

	var queryString4 = "?fid=" + fid;	ajaxRequest4.open("GET", "../tv/indextest.php" + queryString4, true);	ajaxRequest4.send(null); 	

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.