Results 1 to 5 of 5

Thread: Ajax + Java Split

  1. #1
    Join Date
    Dec 2007
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Ajax + Java Split

    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

    Code:
    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

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    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.
    Code:
    text.split('delimiter')
    so for an example
    Code:
    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
    Code:
    || 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

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

  3. #3
    Join Date
    Dec 2007
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    you would put it where you are updating your page... it looks like that point is
    Code:
                    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

  5. #5
    Join Date
    Dec 2007
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I made it
    But i use another way:
    Code:
                    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •