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)