Forum Moderators: open
<script type="text/javascript" src="../framework/jquery.js"></script>
<script type="text/javascript" src="../framework/ui/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../framework/ui/js/jquery-ui-1.7.2.custom.min.js"></script>
//some css'es
<script type="text/javascript">
//<![CDATA[
var data = new Array();
$(function() {
$("#tabs").tabs();
$('#resetview').hover(
function(){
$(this).addClass("ui-state-hover");
},
function(){
$(this).removeClass("ui-state-hover");
}
);
$('#animaltab').click(function(){
$('#accordionanimal').accordion({header: 'h1'});
var e=document.getElementsByName("autoheight");
for(var i=0;i<e.length;i++){e[i].style.height = "550px";}
});
$('#planttab').click(function(){
$('#accordionplant').accordion({header: 'h1'});
var e=document.getElementsByName("autoheight");
for(var i=0;i<e.length;i++){e[i].style.height = "550px";}
});
setTimeout(downloading, 500);
});
function deeplink(event,id,is_plant,is_proc){
if(is_proc == undefined){
is_proc = false;
}
if(is_plant == undefined){
is_plant = true;
}
if(is_plant == true){
$('#tabs').tabs('option', 'selected', 1);
$("#planttab").click();
} else {
$('#tabs').tabs('option', 'selected', 2);
$("#animaltab").click();
}
if(!isNaN(id)){
changetexts(event,id,is_proc);
}
};
function changetexts(event,id,is_proc){
if(is_proc == undefined){
is_proc = false;
}
if($("#tabs").tabs("option","selected") == 1){
elem_id = "accplan";
name = "plant";
}
if($("#tabs").tabs("option","selected") == 2){
elem_id = "accanim";
name = "animal";
}
if(is_proc){
suffix = "proc";
} else {
suffix = "part";
}
var type = typeof window.data[suffix][id];
alert(type+" "+suffix+" "+elem_id+" "+name+" "+id);
document.getElementById(elem_id+"_title").innerHTML = window.data[suffix][id].title;
document.getElementById(elem_id+"_body").innerHTML = window.data[suffix][id].body;
if(window.data[suffix][id].ICID != null){
document.getElementById("images"+name).innerHTML = window.data["img"][window.data[suffix][id].ICID].filecont;
}
if(window.data[suffix][id].links[0] != undefined){
var i = 0;
var linkstext = "";
while(window.data[suffix][id].links[i] != undefined){
linkstext=linkstext+"<li><a href=\"#\" onclick=\"changetexts(event,"+window.data[suffix][id].links[i]+"\">"+window.data["part"][window.data[suffix][id].links[i]].title+"</a></li>";
i++;
}
document.getElementById(elem_id+"_rel").innerHTML = linkstext;
}
if(window.data[suffix][id].processes[0] != undefined){
var i = 0;
var proctext = "";
while(window.data[suffix][id].processes[i] != undefined){
proctext=proctext+"<li><a href=\"#\" onclick=\"changetexts(event,"+window.data[suffix][id].processes[i]+"\">"+window.data["proc"][window.data[suffix][id].processes[i]].title+"</a></li>"; i++;
}
document.getElementById(elem_id+"_proc").innerHTML = proctext;
}
};
function loading(){
document.getElementById("loadtext").innerHTML = "Loading...";
setTimeout(continueloading, 2000);
};
function downloading(){
document.getElementById("loadtext").innerHTML = "Downloading files...";
setTimeout(loading, 2000);
};
function continueloading(){
$("#loading").hide();
document.getElementById("page").style.visibility = "visible";
};
function getpart(){
var data0 = new Array();
$.getJSON("downloadpart.php",{get:""},
function(returned_data)
{
data0 = returned_data;
alert(odump(returned_data));
}
);
return data0;
};
function getimg(){
var data1 = new Array();
$.getJSON("downloadimages.php",{get:""},
function(returned_data)
{
data1 = returned_data;
alert(odump(returned_data));
}
);
return data1;
};
function getproc(){
var data2 = new Array();
$.getJSON("downloadproc.php",{get:""},
function(returned_data)
{
data2 = returned_data;
alert(odump(returned_data));
}
);
return data2;
};
function getdata(){
var data = new Array();
$.getJSON("downloadpart.php",{get:"get"},
function(returned_data)
{
alert("part");
data["part"] = returned_data;
}
);
data["img"] = getimg();
data["proc"] = getproc();
return data;
};
var data = getdata();
//]]>
</script>
Here the server side:
downloadpart.php
<?php
declare(encoding='utf-8');
require_once($_SERVER['DOCUMENT_ROOT']."/beta/includes/headers.inc.php");
$sql = 'SELECT * FROM `bio_part`';
$result = $dblink->query($sql);
$data = array();
for($i=0;$i<$result->num_rows;$i++){
$data_temp = $result->fetch_assoc();
$data[$data_temp["TCID"]] = $data_temp;
$data[$data_temp["TCID"]]["body"]= nl2br($data[$data_temp["TCID"]]["body"]);
$data[$data_temp["TCID"]]["links"]= explode("¦",$data[$data_temp["TCID"]]["links"]);
$data[$data_temp["TCID"]]["processes"]= explode("¦",$data[$data_temp["TCID"]]["processes"]);
}
$ser = array("\"\"","{","}");
$rep = array("null","[","]");
echo str_replace($ser,$rep,php_json_encode($data));
?>
downloadproc.php
<?php
declare(encoding='utf-8');
require_once($_SERVER['DOCUMENT_ROOT']."/beta/includes/headers.inc.php");
$sql = 'SELECT * FROM `bio_proc`';
$result = $dblink->query($sql);
$data = array();
for($i=0;$i<$result->num_rows;$i++){
$data_temp = $result->fetch_assoc();
$data[$data_temp["TCID"]] = $data_temp;
$data[$data_temp["TCID"]]= $result->fetch_assoc();
$data[$data_temp["TCID"]]["body"]= nl2br($data[$data_temp["TCID"]]["body"]);
$data[$data_temp["TCID"]]["links"]= explode("¦",$data[$data_temp["TCID"]]["links"]);
}
$ser = array("\"\"","{","}");
$rep = array("null","[","]");
echo str_replace($ser,$rep,php_json_encode($data));
?>
downloadimg.php
<?php
declare(encoding='utf-8');
require_once($_SERVER['DOCUMENT_ROOT']."/beta/includes/headers.inc.php");
$sql = 'SELECT * FROM `bio_img`';
$result = $dblink->query($sql);
$data = array();
for($i=0;$i<$result->num_rows;$i++){
$data_temp = $result->fetch_assoc();
$data[$data_temp["TCID"]] = $data_temp;
$data[$data_temp["TCID"]]= $result->fetch_assoc();
$data[$data_temp["TCID"]]["filecont"]=file_get_contents("images/".$data[$data_temp["TCID"]]["FILENAME"]);
}
$ser = array("\"\"","{","}");
$rep = array("null","[","]");
echo str_replace($ser,$rep,php_json_encode($data));
?>
the script return json object form serveral lines in the database but they don't showup when I use changetexts to change the text in certain div's on my page
actual page we're lookling at: < removed - see Forum Charter [webmasterworld.com] >
BTW some extra tips?
Greetings MrHaan
[edited by: tedster at 6:41 pm (utc) on Oct. 31, 2009]
preg_replace("/[\n\r]/","",php_json_encode($data));
and altered the ajax code:
function getpart(){
$.ajax({
url: "downloadpart.php",
async: false,
dataType: "json",
success: function(data){
//alert("success parts");
data0 = data;
},
error: function(e,xhr){
alert(e+" "+xhr);
}
}
);return data0;
};