A simple test case is required.
Html code:
Code
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> </title>
<Script src = "jquery-latest.js"> </script>
<Script type = "text/javascript">
Function GetJson (){
$. Ajax ({
Type: "get", // use the get method to access the background
DataType: "json", // return data in json format
Url: "testjson. asp", // background address to be accessed
Data :{
"Keyword": $ ("# keyword") [0]. value
}, // The data to be sent
Success: function (data) {// data is the returned data. Bind The data here.
$ ("# TMPRELATIVE"). empty ();
$. Each (data, function (n ){
Var str = '<div class = "entry"> ';
Str + = '<div class = "text">' + this. id + '</div> ';
Str + = '<div class = "value">' + this. title + '</div> ';
Str + = '</div> ';
$ ('# TMPRELATIVE'). append (str );
});
},
Error: function (){
// Alert ("error ");
}
});
}
</Script>
</Head>
<Body>
<Input type = "text" name = "keyword" id = "keyword"/>
<Input type = "button" id = "btn1" onclick = "GetJson ();" value = "search">
<Div id = "TMPRELATIVE">
</Div>
</Body>
</Html>
Then, json data is returned by testJson. asp. Here two classes are found to operate json (JSON_2.0.2.asp, JSON_UTIL_0.1.1.asp)
Code
<% @ CODEPAGE = 65001%>
<! -- # Include file = "JSON_2.0.2.asp" -->
<! -- # Include file = "JSON_UTIL_0.1.1.asp" -->
<%
Response. CodePage = 65001
Response. Charset = "UTF-8"
Response. CacheControl = "no-Cache"
Key = Request. QueryString ("keyword ")
Set conn = Server. CreateObject ("Adodb. Connection ")
Conn. ConnectionString = "Provider = SQLOLEDB; Data Source = 192.168.1.20; UID = sa; PWD = 123456; Initial Catalog = turbocms_6008 ;"
Conn. Open
SQL _str = "SELECT top 10 id, title, submitdate, url FROM cms_content where keyword like '%" & key & "% '"
Response. Write QueryToJSON (conn, SQL _str). Flush
%>
The two files JSON_2.0.2.asp and JSON_UTIL_0.1.1.asp are attached.