Click here to Skip to main content
15,884,849 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am getting all the records from a xml file to a table using the follwing code
JavaScript
function view() {
    var xhr = new XMLHttpRequest();
    
    xhr.open("POST", "http://localhost:49989/WebService1.asmx/AllProduts", true);
    
    xhr.onreadystatechange = function () {
    
        if (xhr.readyState == 4 && xhr.status == 200) {
            var doc = $.parseXML(xhr.responseText);
            var $xmlresponsetree = $(doc);
    
            var rows = "";
            $xmlresponsetree.find("products").each(function () {
    
    
    
                rows += "<tr><td>" + $(this).find("productid").text() + "</td>";
                rows += "<td>" + $(this).find("Productname").text() + "</td>";
                rows += "<td>" + $(this).find("Categoryname").text() + "</td>";
                rows += "<td>" + $(this).find("Unitprice").text() + "</td>";
                rows += "<td>" + $(this).find("Productdescription").text() + "</td>";
                rows += "<td>" + $(this).find("Availablestock").text() + "</td></tr>";
    
    
            })
    
            document.getElementById('results').innerHTML = rows;
    
        }
    }
    xhr.send();
}

but i need to impliment searching, sorting,filtering by a dropdown or something
can some one please help me asap
Posted
Updated 28-May-14 16:45pm
v2

 
Share this answer
 
v2
this is the code for search..
in this xml file is in a different server.

C#
function search() {
            var xhr = new XMLHttpRequest();

            var query = document.getElementById("searchText").value;

            var regex = new RegExp(query,"i");

            xhr.open("POST", "http://localhost:49989/WebService1.asmx/AllProduts", true);

            xhr.onreadystatechange = function () {

                if (xhr.readyState == 4 && xhr.status == 200) {
                    var doc = $.parseXML(xhr.responseText);
                    var $xmlresponsetree = $(doc);


                    var rows = "";
                    $xmlresponsetree.find("products").each(function () {


                        if ($(this).find("Productname").text().match(regex)) {
                            rows += "<tr><td>" + $(this).find("productid").text() + "</td>";
                            rows += "<td>" + $(this).find("Productname").text() + "</td>";
                            rows += "<td>" + $(this).find("Categoryname").text() + "</td>";
                            rows += "<td>" + $(this).find("Unitprice").text() + "</td>";
                            rows += "<td>" + $(this).find("Productdescription").text() + "</td>";
                            rows += "<td>" + $(this).find("Availablestock").text() + "</td></tr>";
                        }

                    })

                    document.getElementById('results').innerHTML = rows;

                }
            }
            xhr.send();
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900