I'm calling a web method from javascript. Web method returns an array of customers from Uttrwaint database is an example of what I am working here:
I do not know how this JavaScript method is to write: CreateCustomersTable Create < / P>
This will create an HTML table to display the data is being retrieved. Would appreciate any help
I Javascript
function GetCustomerByCountry () {var countries = $ get ( "txtCountry") value. AjaxWebService.GetCustomersByCountry (Country, OnWSRequestComplete, OnWSRequestFailed); } ONWSRequestComplete function (results) {if (result! = Tap) {CreateCustomersTable (results); // GetMap (Results); }} CreateCustomersTable function (warning) {warning (result); If (document.all) // IE filter for DOM because other browsers are limited {// How do I do this? }} And {$ get ("divOutput"). InnerHTML = "RSS only available in IE5 +"; }}
My Web Method
[WebMethod] public client [] GetCustomersByCountry (String country) {NorthwindDALTableAdapters.CustomersTableAdapter adap = new NorthwindDALTableAdapters.CustomersTableAdapter () ; Northwind Dale Client DataTable = adap.GetCustomersByCountry (Country); If (dt.rows.Count & lt; = 0) {return tap; } Customers [] customers = new customer [dt.rows.Count]; For (int i = 0; i & LT; dt.Rows.Count; i ++) {NorthwindDAL.CustomersRow line = (NorthwindDAL.CustomersRow) dt.Rows [i]; Customer [i] = new customer (); Customers [i] Client ID = Row Customer ID; Customers [I] .name = Row Contact; } Returning customers; } Try
When the result variable value in debug mode. If the structure I think the structure looks, it could do some work:
function CreateCustomersTable (result) {var str = '& lt; Table & gt; '; Str + = '& lt; TR & gt; Id & lt; / Th & gt; & Lt; Th & gt; Name & lt; / Th and gt; & Lt; & Lt; Th & gt / TR & gt; '; For 'str + = (; I & lt; result.length i ++ above I = 0)' & lt; TR & gt; & Lt; TD & gt; + Result [i] .CustomerId + '& lt; / TD & gt; & Lt; TD & gt; + Result [i] .name + '& lt; / Td> & Lt; / Tr & gt; '; } Str + = '& lt; / Table & gt; '; Return str; }
And then you can do anything like this:
var current dive = document.getElementById ('ID of an existing div)' ; Existing developer HTML = CUSTOMERTables (results);
I want your help.
Comments
Post a Comment