調取jSon資料--展示,調取json--

來源:互聯網
上載者:User

調取jSon資料--展示,調取json--

以下代碼是將頁面中的展示部分

function searchProductlistByfilterCondition(index, type, sort, filterWord) {       //cite_html    var citem_html = '<div class="citem"><div class="citemtop">'                    + '<a href="" target="_blank"><img src="{imgList}" /></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></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="">'                    + '<img width="24" height="24" src="images/main/1408603734394.jpg" />'                    + '<span class="txtellipsis">{user}</span> </a></div>'                    + '<span class="fcfiled">( <a target="_blank" href="">轉載</a>- <a target="_blank" href="">'                    + ' 站酷中國</a> )</span>'                    + '<div id="hiddenpopop" class="miniprofile bottom"><div class="mnphead">'                    + '<a target="_blank" href="">'                    + ' <img src="images/main/author.jpg" width="50" height="50" /></a><div><p>'                    + ' <span class="mnpw-1">小海藻</span> <span class="mnpw-2">福建 福州</span> '                    + ' <span class="mnpw-3">人氣:<span>256</span></span></p><p class="fmbtn mt10">'                    + ' <a target="_blank" href="" class="ufmbtn ufocus"><span class="yy-icon yy-ufocicon"></span>'                    + ' <span>加關注</span> </a><a target="_blank" href="" class="ufmbtn ml10 ufusm"><span class="yy-icon yy-ufusm">'                    + ' </span><span>發私信</span> </a></p></div></div><div class="cb"></div>'                    + ' <div class="mnpbody mt10">'                    + ' <a target="_blank" href="">'                    + ' <img src="images/main/1.jpg" width="105" height="68" />'                    + ' </a><a target="_blank" href="">'                    + ' <img src="images/main/1.jpg" width="105" height="68" />'                    + ' </a><a target="_blank" href="">'                    + ' <img src="images/main/1.jpg" width="105" height="68" />'                    + ' </a></div></div></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:頁面代碼(關鍵字用特殊符號和文字表示,例如 {imgList},(time)等)

$.get():從指定的資源請求資料

第一個參數:jSon外掛程式;第二個參數:json資料格式;第三個參數:function(data)方法,data為取得的json資料串

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

data.jsona:json資料

function(index,elem):index:索引       elem:相當於json資料串

此後,將html代碼添加到頁面中。

此方法的作用:1、傳遞參數 2、擷取3、展示

接下來在

$(function () {    //頁面初始化調用    searchProductlistByfilterCondition("", "", "", "");        //查詢方塊,關鍵字查詢--調用函數    $('#search ').click(function () {        pageIndex = 1;        searchProductlistByfilterCondition(pageIndex, sortP, typeL, keyWord);          });}

頁面js中,調用,只需要將具體的資料對應填上就可以了。

頁面中的js作用:1、綁定 2、賦值

此上為自己的一點認知,如果有什麼不對的地方,還希望大家給於指點哦!


問下java中封裝了json資料,在js中怎擷取json資料來頁面展示?

你用的是response.sendRedirect執行的跳轉(不是foward),那麼如果你這個index.jsp和你的java檔案在一個project項目裡的(術語叫同一個域內)。
1.用session來儲存java裡的json,無論是json object還是String格式的json. 用setAttribute方法放到Session裡面,然偶跳轉到index,jsp

2.在jsp裡同樣用session.getattribute獲得這個json資料,放到表單的某個位置,比如說放到文字框內,作為文字框的value.

3.jsp裡面的js代碼,getElementById或者這個文字框的value,然後alert出來
 
java中封裝了json資料,在js中怎擷取json資料來頁面展示

首先你沒把json資料類型的格式給弄清楚。json=[{'key':value},{'key':value}];的形式存在的.前台只需要擷取到json後直接json.key即可.
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.