Click here to Skip to main content
15,886,857 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
plz help i want to data fetch from database onclick function using javascript c#
Posted

You can call the web service from javascript. Please check the article below.
Calling ASP.NET Webservice using JavaScript on Regular Interval of Time[^]

You can avoid below code in the article, as this would not be required in your case.
C#
$(document).ready(function () {
           setInterval("CallWebService()", 2000);
       });
 
Share this answer
 
v2
Comments
Nishant.Chauhan80 8-Jan-15 3:05am    
i want to fetch using javascript
See using jquery or javascript you can call webmethod which is a ajax call to the server.In that webmethod you can fetch the data and keep the table in dataset and return ds.GetXml() from that webmethod.

and you will get table(s) in your javascript and then you can do whatever you want with that data.

use $.ajax

use this as your reference.
Here getUnitsViewTable is a webmethod

XML
var getUnitsViewTable = function () {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "AHUDialog.aspx/getUnitsViewTable",
        data: "{}",
        dataType: "json",
        complete: function (jqXHR) {
            var returnedData = JSON.parse(jqXHR.responseText).d;
            var xmlDoc = $.parseXML(returnedData);
            var xml = $(xmlDoc);
            var tableData = xml.find("Table");
            var str = "";
            unitsTable = $(document.createElement('table'));
            str += "<tbody><tr><th>B</th><th>Model</th></tr>"
            $(tableData).each(function () {
                str += "<tr>";
                str += "<td>" + $(this).find('B').text() + "</td>";
                str += "<td>" + $(this).find('Model').text() + "</td>";
                str += "</tr>";
            });
            str += "</tbody>";
            unitsTable.append(str);
           
        }
    });
}
 
Share this answer
 

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