jquery calls WCF directly, service-oriented SOA architecture (third day)

Source: Internet
Author: User

The so-called everything has, only owes the East wind!! Next is the call to WCF,

First, under the client, write a random HTML page, and then write the following method:

<script src= "Scripts/jquery.min.js" ></script>---You have to import the jquery plugin first.

The following method is to get the relative path of the website

$.getrooturl = function () {
return Window.location.protocol + "//" + window.location.host;
}

Next we'll write a JS method

  function getdate () {            var url = $.getrooturl () + "/webservice.svc/operate/select";    This is the way we're visiting.
This is the name of the database.
var database = "VBK";
This is the name of the method we're going to execute backstage.
var method = "Select"; Here is the SQL statement you want to write

var sql = $ ("#txt_sql"). Val (); $.ajax ({ url:url, contentType: "Application/json",
Data: ' {' database ': ' VBK ', ' method ': ' Select ', ' SQL ': ' ' +sql+ ' ' "} ', type: ' Post ', success:function (data) { var datatable = eval (data) [0].data; var html = jsontotable (DataTable); $ ("#table"). HTML (HTML); }, error:function (err) { $ ("#table"). HTML (err.responsetext); } }); }

The next thing we need to do is make the query easier: (directly convert the JSON data to a table)

function jsontotable (JSON) {varcols =NewArray (); $.each (json[0], function (index, value) {//Cols[cols.length] = value;Cols.push (index);            }); sHTML="<table border=1><tr>";//Create header Row-save HTML of table in sHTML             for(i =0; i < cols.length; i++) {shtml+="<th>"+ Cols[i] +"</th>"; } shtml+="</tr>"; //var irowmax = myJSONobj.records.length;             for(IRow =0; IRow < Json.length; irow++) {//Add the RowssHTML + ="<tr>";  for(i =0; i < cols.length; i++) {shtml+="<td>"+ $ (Json[irow]). attr ([cols[i]]) +"</td>"; } shtml+="</tr>"; } shtml+="</table>"; returnshtml; }

In addition I attach the body inside the code:

<body> <input type="text"style="width:200px"Id="Txt_sql"Value="SELECT * FROM dbo. Mdcdatkanban"/> <input type="Button"Value="Get Data"onclick="getdate ()"/> <div id="Table"> </div></body>

Next we look at the effect: (also tell everyone, due to different computer configuration, modify your configuration file can be used)

Write your SQL statement and click Get data to see what you want to write.

VS2012 version Source Download:

Http://files.cnblogs.com/files/liujing379069296/Vs2012Client.rar

vs2010 Source Download

Http://files.cnblogs.com/files/liujing379069296/VS2010Client.rar

jquery calls WCF directly, service-oriented SOA architecture (third day)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.