Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [advAJAX] Przetwarzanie pobranego XMLa
Seth
post 21.06.2006, 22:20:46
Post #1





Grupa: Przyjaciele php.pl
Postów: 2 335
Pomógł: 6
Dołączył: 7.03.2002

Ostrzeżenie: (0%)
-----


Do pobierania danych i wyswietlania go w tabeli uzywam zmodyfikowanego przykladu ze strony Anakina:
http://advajax.anakin.us/phpsolutions/2.html

Wszystko pieknei dziala ale mam jedno pytanie:
Dlaczego gdy XML nie jest w jednej linii nie zostaje sparsowany?


Mam takze jeden maly problem, takze z XMLem.
Po zmodyfikowaniu JSa:

Kod
    var currentPage = 0;
    var currentSort = "companyName";
    var currentSortOrder = "ASC";
    var maxPage;
    var defaultTableData;
    
    function $(id) {
        return document.getElementById(id);
    }
    
    function recordClick(obj) {
        alert(obj.id);        
    }
    
    function parseRecords(xml) {

        with (xml.getElementsByTagName("records").item(0)) {
            page = getAttribute("page")*1;
            maxPerPage = getAttribute("max_per_page");
            startId = maxPerPage*page+1;
            total = getAttribute("total")*1;
            maxPage = Math.ceil(total/maxPerPage);
        }
        
        
        $("btnFirst").style.visibility = $("btnPrev").style.visibility = page == 0 ? "hidden" : "visible";
        $("btnLast").style.visibility = $("btnNext").style.visibility = page+1 == maxPage ? "hidden" : "visible";
        
        d = $("dataTable");
        for (i = d.rows.length-1; i >= 0; i--)
          d.deleteRow(i);
        record = xml.getElementsByTagName("record");
        result = "";
        
        for (i = 0; i < record.length; i++) {
            tr = document.createElement("tr");
            td = document.createElement("td");
            

                 if (i % 2 == 0) {
                     tr.className = "dark";
                 } else {
                     tr.className = "light";
                 }

                for (j = 0; j < 5; j++) {
                if (j == 0) {
                    tr.id = record[i].childNodes[j].childNodes[0].nodeValue;;
                    tr.setAttribute('onclick', 'recordClick(this)');
                    tr.style.cursor = "pointer";
                } else {
                td = document.createElement("td");
                td.innerHTML = record[i].childNodes[j].childNodes[0].nodeValue;
                tr.appendChild(td);
                }
            }
            d.appendChild(tr);
        }

        return result;
    }
    
    function initSearchForm() {
        advAJAX.assign(document.getElementById("searchForm"), {
            onInitialization : function() {
                $("dataStats").innerHTML = '<span>Searching...</span>';
                $("btnPrev").style.visibility = "hidden";
                $("btnNext").style.visibility = "hidden";
                $("btnFirst").style.visibility = "hidden";
                $("btnLast").style.visibility = "hidden";
            },
            
            onSuccess : function(obj) {
                $("dataStats").innerHTML = "";
                parseRecords(obj.responseXML);
                       addTableRolloverEffect('resultTable','rollover','');
            },
            

        onError : function(obj) {
            alert('dupa');
        }
            
        });
    }


...IE przestalo mi parsowac XMLA (FF, Opera dziala w porzadku).
No i nie mam pojecia co tu jest nie tak, gdyz IE odebral porpawnie sformatowany XML, ale podczas parsowania wywala blad (typu 'null' is not defined).
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 09:18