Use jQuery to operate simple JSON data

Source: Internet
Author: User

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.

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.