使用jQuery / ajax pasing参数调用json文件

时间:2016-01-08 02:44:32

标签: jquery json ajax

只想问一下如何用参数调用json文件?

以前,我一直在使用php并转换为json。

这是jQuery脚本:

$("#btnKeyword").on("click",function(){

    var param = document.getElementById('inputKeyword').value;

    alert(param);

    $.ajax({
        type: "GET",
        url: "./php/scr1.php",
        data:{ keyword: param},
        success: function (data) {

            for(var i=0; i<data.length; i++){
            var no = i+1;
            $table ="<tr class='row-parent' data-toggle='modal' data-target='#myModal'>";
            $table += "<td align='right'>"+no+ "</td>";
            $table += "<td  class='id'>"+data[i].uid+ "</td>";
            $table += "<td>"+data[i].document_id+ "</td>";
            $table += "<td>"+data[i].activity+ "</td>";
            $table += "<td>"+data[i].date_time+ "</td>";
            $table +="</tr>";

            $("#docLoc").append($table);
            }               
        },error: function (xhr, ajaxOptions, thrownError) {alert("ERROR:" + xhr.responseText+" - "+thrownError);}
    });
});

我的json文件2.json。

如何在json文件中执行条件

[

{

    "id": "7",
    "uid": "287",
    "document_id": "X85BMaJe6,",
    "activity": "2",
    "date_time": "10-12-2015 17:29:04"

},
{

    "id": "9",
    "uid": "288",
    "document_id": "X85BMxJe6,",
    "activity": "2",
    "date_time": "15-12-2015 09:59:49"

},

    {
        "id": "11",
        "uid": "289",
        "document_id": "X45CMxJe6,",
        "activity": "2",
        "date_time": "17-12-2015 15:16:04"
    }

]

希望这可以提供帮助

先谢谢你帮助我..

1 个答案:

答案 0 :(得分:0)

json文件是静态资源,除非您在服务器上使用编程语言来读取并传递它,否则它将永远是静态资源。

如果要在浏览器中过滤该文件的结果,则需要使用<div id="C"> <div id="A">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eligendi odit cumque animi cum recusandae reprehenderit labore incidunt necessitatibus. lorem</div> <div id="B"> <div id="D"> Dragée topping pastry cake liquorice. Oat cake cake dessert brownie caramels candy muffin. Jelly jelly beans gummies sugar plum oat cake. <br> <br>Fruitcake croissant candy canes gingerbread fruitcake brownie donut cookie. Donut gummi bears biscuit wafer ice cream sesame snaps. Tart ice cream biscuit jelly croissant candy. Marshmallow jelly tiramisu carrot cake apple pie cupcake dragée pudding lollipop. <br>Ice cream bear claw pastry powder danish. Oat cake chocolate cake sesame snaps topping bear claw caramels cake tiramisu. Icing muffin bonbon dragée sweet roll jujubes danish. Macaroon cake candy chupa chups bear claw chocolate bar muffin cookie. <br> <br>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam similique eligendi iste laudantium nisi eius velit odio dolores sit autem, quod corrupti quisquam tenetur doloribus, commodi obcaecati, fugit at nam?</div> </div> </div>Array.prototype.filter()Array.prototype.map()等数组方法来执行此操作