Introduction
A few months back, I got a requirement to fetch some inventory data from a server and show it to an HTML page. The interesting fact was the client server (the one that I want to show the data in) does not support .Net files. If did support them then we could directly add the web references and display the data. So what to do? I tried JSONP and Angular JSON but I could not make it to work. Then I came up with an idea.
- A web service that gets the data from the SQL Server 2008 DB in HTML format.
- One HTML file where we need to show the data.
- jQuery latest version JavaScript file.
Using the code
So let's start.
Make an HTML table in the file like the following:
- <table id="inventory">
- <tr id="maintr">
- <th>
- LOCATION </td>
- <th>
- 20 GP </td>
- <th>
- 40 FC </td>
- <th>
- 40 GP
- </th>
- <th>
- 40 OT
- </th>
- <th>
- 40 HCGP
- </th>
- </tr>
- </table>
- <script type="text/javascript" src="js/jquery-1.9.1.js"></script>
- <style type="text/css">
- #inventory
- {
- font-family: "Trebuchet MS" , Arial, Helvetica, sans-serif;
- width: 600px;
- border-collapse: collapse;
- }
- #inventory td
- {
- font-size: 10pt;
- border: 1px solid #25aacc;
- padding: 3px 7px 2px 7px;
- }
- #inventory th
- {
- font-weight: bold;
- font-size: 10pt;
- text-align: left;
- padding-top: 5px;
- padding-bottom: 4px;
- background-color: #25aacc;
- color: #fff;
- padding: 3px 7px 2px 7px;
- border: 1px solid #25aacc;
- }
- #inventory tr.normal td
- {
- font-size: 10pt;
- color: #000;
- background-color: #ecf6f8;
- }
- #inventory tr.alt td
- {
- font-size: 10pt;
- color: #000;
- background-color: #c0e6ef;
- }
- </style>
- <script type="text/javascript">
- var gp20;
- var gp40;
- var fc40;
- var ot40;
- var hcgp40;
- $(document).ready(function () {
- $("#accordion").accordion();
- $.post("RetWS.php", {
- action: "test"
- },
- function (data) {
- var className;
- var i = 0;
- var xdoc = $.parseXML(data),
- $xml = $(xdoc);
- $($xml).find('AvailableSaleUnitsDetail').each(function () {
- if (i % 2 != 0) {
- className = 'alt';
- }
- else {
- className = 'normal';
- }
- if (parseInt($(this).find('_x0032_0GP').text()) > 50) {
- gp20 = '50 +';
- }
- else {
- gp20 = $(this).find('_x0032_0GP').text();
- }
- if (parseInt($(this).find('_x0034_0FC').text()) > 50) {
- fc40 = '50 +';
- }
- else {
- fc40 = $(this).find('_x0034_0FC').text();
- }
- if (parseInt($(this).find('_x0034_0GP').text()) > 50) {
- gp40 = '50 +';
- }
- else {
- gp40 = $(this).find('_x0034_0GP').text();
- }
- if (parseInt($(this).find('_x0034_0OT').text()) > 50) {
- ot40 = '50 +';
- }
- else {
- ot40 = $(this).find('_x0034_0OT').text();
- }
- if (parseInt($(this).find('_x0034_0HCGP').text()) > 50) {
- hcgp40 = '50 +';
- }
- else {
- hcgp40 = $(this).find('_x0034_0HCGP').text();
- }
- $("#inventory").append("<tr class=" + className + " ><td id=" + $(this).find('Location').text() + ">" + $(this).find('Location').text() + "</td> <td>" + gp20 + "</td><td >" + fc40 + "</td> <td>" + gp40 + "</td><td >" + ot40 + "</td><td >" + hcgp40+ "</td> </tr>");
- i++;
- });
- })
- });
- </script>
In the RetWs.php you can do the following codes:
- <?php
- if(isset($_POST['action']) && !emptyempty($_POST['action'])) {
- $action = $_POST['action'];
- switch($action) {
- case 'test' : doWebService();
- break;
- }
- }
- function doWebService()
- {
- $client = new SoapClient("http://Here paste link to your webservice");
- echo $client->getInventoryForWs()->getInventoryForWsResult;
- }
- ?>
http://www.something.com/Reports/Marketing/Mywebservice.asmx?WSDL
Make sure that there are no spelling mistakes.

Sibeesh VenuPosted Aug 7, 2015, 2:15 AM
Ankit Bansal Thank you
Ankit BansalPosted Aug 7, 2015, 2:12 AM
nice...thanks for share..
Sibeesh VenuPosted Aug 7, 2015, 1:07 AM
Upendra Pratap Shahi Thank you
Upendra Pratap ShahiPosted Aug 7, 2015, 1:07 AM
good sir..