Retrieve jSon data -- display, retrieve json --

Source: Internet
Author: User

Retrieve jSon data -- display, retrieve json --

The following code shows the page

Function searchProductlistByfilterCondition (index, type, sort, filterWord) {// cite_html var citem_html = '<div class = "citem"> <div class = "citemtop">' + '<a href = "" target = "_ blank">  </a> <div class = "citemtxt"> '+' <a class = "citemtitle" target = "_ blank" href = ""> {title} </a> <div class = "citemtc"> '+' <span class = "yy-icon yy-time txtellipsis"> {time} </span> '+' </div> '+' <div class = "citemqt"> '+' <span class = "yy-icon yy-view ">{mark} </span> <span class =" yy-icon yy-comment ">{price} </span> '+' <a class =" yy-icon yy-like "href =" "> <span> {praise} </span> </a> </div> '+' <div class =" citemqt citemfoot "> <div class =" citemzl "> <a class =" citemimg "href =" "> '+'  '+' <span class = "txtellipsis" >{user} </span> </a> </div> '+' <span class = "fcfiled"> (<a target = "_ blank" href = ""> reprint </a>-<a target = "_ blank" href = ""> '+' station cool China </a>) </span> '+' <div id = "hiddenpopop" class = "miniprofile bottom"> <div class = "mnphead"> '+' <a target = "_ blank" href = ""> '+'  </a> <div> <p> '+' <span class = "mnpw-1"> seaweed </span> <span class = "mnpw-2"> Fuzhou, Fujian </span> '+' <span class =" mnpw-3 "> popularity: <span> 256 </span> </p> <p class = "fmbtn mt10"> '+' <a target = "_ blank" href = "" class = "ufmbtn ufocus"> <span class = "yy-icon yy-ufocicon"> </span> '+' <span> ADD Attention </span> </a> <a target = "_ blank" href = "" class = "ufmbtn ml10 ufusm"> <span class = "yy-icon yy-ufusm"> '+' </span> <span> send a private message </span> </a> </p> </div> <div class = "cb"> </div> '+ '<div class = "mnpbody mt10">' + '<a target = "_ blank" href = "">' + ' '+' </a> <a target = "_ blank" href = ""> '+'  '+' </a> <a target = "_ blank" href = ""> '+'  '+' </a> </div> </div> '; $. get ('ajax/getProductListByFliterCondition. ashx', {pageIndex: index, Type: type, Sorting: sort, keyWord: filterWord}, function (data) {$. each (data. jsona, function (index, elem) {citemHtml + = citem_html.replace ('{imgList}', elem. msg_img_list ). replace ('{title}', elem. msg_title ). replace ('{time}', elem. msg_date ). replace ('{mark}', elem. msg_mark ). replace ('{price}', elem. msg_price ). replace ('{praise}', elem. msg_praise ). replace ('{user}', elem. msg_create_user);}) $ ("# fsD1 "). after (citemHtml) ;}, 'json'); // alert (sort );}

Citem_html: Page code (keywords are represented by special symbols and text, such as {imgList} And (time)

$. Get (): request data from the specified resource

The first parameter is the jSon plug-in. The second parameter is the json data format. The third parameter is the function (data) method. data is the obtained json data string.

$. Each (data. jsona, function (index, elem ))

Data. jsona: json data

Function (index, elem): index elem: equivalent to json data string

Then, add the html code to the page.

The role of this method: 1,PASS Parameters2,Obtain3,Display

Next

$ (Function () {// page initialization call searchProductlistByfilterCondition ("", ""); // query box, keyword query -- call the function $ ('# search '). click (function () {pageIndex = 1; searchProductlistByfilterCondition (pageIndex, sortP, typeL, keyWord );});}

In page js, you only need to fill in the corresponding data.

Js functions on the page: 1,Bind2,Assignment

Here is my own perception. If there is anything wrong, I hope you can give some advice!


Question: How can I obtain json data in JavaScript to display on the page?

You are using response. the jump (not foward) of sendRedirect execution, if your index. jsp and your java files are in a project (the term is the same domain ).
1. Use session to store json in java, whether it is json object or json in String format. Use the setAttribute method to put it in the Session, and even jump to index, jsp

2. Use session. getattribute in jsp to obtain the json data and place it in a certain position of the form. For example, put it in the text box as the value of the text box.

3. js code in jsp, getElementById or the value of this text box, and then alert

Java encapsulates json data. How can I obtain json data in js to display it on pages?

First, you have not figured out the format of the json data type. Json = [{'key': value}, {'key': value}];. The front-end only needs to obtain json and then directly use json. key.

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.