English 中文(简体)
如何在每一个标签中显示 json 数据 。
原标题:how to display json data fetched using ajax in each tab

我有一个 2 级行动组 使用一种返回json 数据的方法。

我有8个 Jsp 标签。 当用户点击一个标签时, 我想用此方法调用 ajax 。 我希望返回的 json 数据能够与 html 进行剖析和装饰, 并在此标签中提供 。

我用jquery标签制做tabs

  • How can I capture the returned json data ? Can I subscribe to some event that jquery publishes ?
  • How can I process the returned json data ? For e.g.; json data:

{城市:{地名=纽约, 化名=纽约, imgPath=文件Path/img1.jgp}}}

I would like to extract the name and bold it. Use the imgPath to define img tag, etc

问题回答
 $(document).ready(function () {
            var data = { "City": [{ "name": "New York1", "alias": "NY1", "imgPath": "filePath/img1.jgp" }, { "name": "New York2", "alias": "NY2", "imgPath": "filePath/img2.jgp" }, { "name": "New York3", "alias": "NY3", "imgPath": "filePath/img3.jgp" }, { "name": "New York4", "alias": "NY4", "imgPath": "filePath/img4.jgp"}] };

            if (data.City.length > 0) {
                $( body ).prepend( <div id="tabs1"><ul></ul></div> );

                $.each(data.City, function (i, entity) {
                    $( #tabs1 ul ).append($( <li><a href="#tabs1-  + (i + 1) +  ">  + entity.name +  </a></li> ));
                    $( #tabs1 ).append( <div id="tabs1-  + (i + 1) +  "><p>Image Path:  + entity.imgPath +  </p></div> );
                });

                $("#tabs1").tabs();
            }
        });​

现场演示见此链接 : http://jsfidle.net/nanoquantumtech/ffbx5/

您可以通过将数据参数传送到 ajax 称成功回调方法来捕捉返回的 Json 数据。 http://api.jquery.com/jQuery.ajax/

您可以使用 jQuery arse.json 方法,并将json 字符串传递给它。 http://api.jquery.com/jQuery.parseJson/

还有一件事,你举的json字串看起来不像有效的字串。 您可以从这个链接 < a href=> http://jsonlint.com/ 上粘贴json数据或粘贴url, 检查json是否有效 。





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签