PDA

View Full Version : Ajax + Java Split



XAKERA
02-11-2008, 10:27 AM
Hello.
I write ajax page request and I can't make split of java.
Please add me responseText.split(||javascript||) like this
this is my sode


var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadstatustext="<center><br><br><br><br><br><img src='pic/ajax-loader.gif' /><br><br><br></center>"
var loadingPanel = new yuiLoadingPanel();

function load(){
loadingPanel.show();
}
function deload(){
loadingPanel.hide();
}

////NO NEED TO EDIT BELOW////////////////////////
var defaultcontentarray=new Object()
var bustcacheparameter = ""
function ajaxpage(page,where){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
load();

var xmlhttp=false; //Clear our fetching variable
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x objectů
} catch (e) {
try {
xmlhttp = new
ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
}
xmlhttp.open('GET', page, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status == 200) { //Check if it is ready to recieve data
var main_div = xmlhttp.responseText; //The content data which has been retrieved ***
if(main_div){ //Make sure there is something in the content variable
document.getElementById(where).innerHTML = main_div; //Change the inner content of your div to the newly retrieved content ****
deload();
}
}
}
xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}
I want it for work javascript in contain page. Thanks

boogyman
02-11-2008, 03:01 PM
Java and Javascript are two different languages. I know it appears you are just writing it in short hand, but write js if you do not want to type out the whole name. Saying "java" will only confuse people.

now as for your code I cannot see where you are trying to split the response, however the correct formatting for splitting in javascript is.

text.split('delimiter')
so for an example

var digits = 0123456789;
var splitIt = digits.split('5');
splitIt[0] = 1234;
splitIt[1] = 6789;

You are just telling the function where to split, so if you wanted the pattern

|| text || text || text || text ||
you would first need to know how to delimit (separate) your responseText,
than you would need to create a loop through the responseText and run the print out script



var text = something.responseText;
var splitText = text.split('delimiter')
for(var i=0;i<splitText.length; i++)
{
document.getElementById(where).innerHTML += '||' + text.split('[COLOR="Red"]delimiter');
}

XAKERA
02-11-2008, 06:44 PM
Thanks for helping.
Can you add me responseText.split in my source? I don;t know where add it? Please add me and post here. Thanks

boogyman
02-11-2008, 09:36 PM
you would put it where you are updating your page... it looks like that point is


var main_div = xmlhttp.responseText; //The content data which has been retrieved ***
if(main_div){ //Make sure there is something in the content variable
document.getElementById(where).innerHTML = main_div; //Change the inner content of your div to the newly retrieved content ****
deload();
}

but only you will know where it is updating

XAKERA
02-12-2008, 08:11 AM
I made it :)
But i use another way:

if(main_div){ //Make sure there is something in the content variable
split_text(xmlhttp,where);
}
And i created this function

function split_text(xmlhttp, where){
if (xmlhttp.readyState == 4 && (xmlhttp.status==200 || window.location.href.indexOf("http")==-1)){
var Result = xmlhttp.responseText.split("||javascript||");
document.getElementById(where).innerHTML=Result[0];
if(Result[1]) eval(Result[1]);
deload()
}
}

Thanks boogyman. You are good man. You gave me way to make it. THanks