I am calling a web Method from javascript. The web method returns an array of customers from the northwind database. The example I am working from is here: Calling Web Services with ASP.NET AJAX
I dont know how to write this javascript method: CreateCustomersTable
This would create the html table to display the data being returned. Any help would be appreciated.
My javascript
function GetCustomerByCountry() { var country = $get('txtCountry').value; AjaxWebService.GetCustomersByCountry(country, OnWSRequestComplete, OnWSRequestFailed); } function OnWSRequestComplete(results) { if (results != null) { CreateCustomersTable(results); //GetMap(results); } } function CreateCustomersTable(result) { alert(result); if (document.all) //Filter for IE DOM since other browsers are limited { // How do I do this? } } else { $get('divOutput').innerHTML = 'RSS only available in IE5+'; } }
My web Method
[WebMethod] public Customer[] GetCustomersByCountry(string country) { NorthwindDALTableAdapters.CustomersTableAdapter adap = new NorthwindDALTableAdapters.CustomersTableAdapter(); NorthwindDAL.CustomersDataTable dt = adap.GetCustomersByCountry(country); if (dt.Rows.Count <= 0) { return null; } Customer[] customers = new Customer[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { NorthwindDAL.CustomersRow row = (NorthwindDAL.CustomersRow)dt.Rows[i]; customers[i] = new Customer(); customers[i].CustomerId = row.CustomerID; customers[i].Name = row.ContactName; } return customers; }
Try to look what is the result variable value in debug mode. If the structure seems the structure that i’m imagining, something like this could work:
And then You can do somethig like this:
I wish this help you.