如何使用ajax jquery方法获取带有复选框的json值?

时间:2019-06-30 09:54:38

标签: javascript jquery json ajax

为什么,我是json,ajax和jquery的新手。我试图用复选框做一个过滤器,它只代表复选框值向我显示结果。例如,如果我单击sharjah,它会向我显示包含sharjah的所有对象,并且与每个城市相同;如果我单击任何其他城市的复选框,它会显示值。

{
   "p1": { 
            "name": "Satish",
            "age":   25,
            "company": "Techntoip",
            "cities": [
                "sharjah",
                "dubai",
                "musaffa"
            ]
         },


   "p2": {
            "name": "Kiran",
            "age":   28,
            "company": "Oracle",
            "cities": [
                "sharjah",
                "dubai",
                "abu dhabi",
                "musaffa"
            ]
         },                           
   "p3": {
            "name": "Kiran",
            "age":   28,
            "company": "Oracle",
            "cities": [
                "sharjah",
                "abu dhabi",
                "musaffa"
            ]
         },                           
   "p4": {
            "name": "Kiran",
            "age":   28,
            "company": "Oracle",
            "cities": [
                "dubai",
                "abu dhabi",
                "musaffa"
            ]
         },                           
   "p5": {
            "name": "Kiran",
            "age":   28,
            "company": "Oracle",
            "cities": [
                "sharjah",
                "dubai",
                "abu dhabi"
            ]
         },                           
   "p6": {
            "name": "Kiran",
            "age":   28,
            "company": "Oracle",
            "cities": [
                "sharjah",
                "dubai",
                "musaffa"
            ]
         }                           
}

这是我的json文件。

C:\Users\sushant dhore>cd C:\Users\sushant dhore\Desktop\myside

C:\Users\sushant dhore\Desktop\myside> py -3.7.3 manage.py startapp main
Unable to create process using 'C:\Users\sushant dhore\AppData\Local\Programs\Python\Python37\python.exe -3.7.3 manage.py startapp main'

1 个答案:

答案 0 :(得分:0)

看看ajax方法jQuery.AJAX

 var inputValue = $(this).val()
    $.ajax({
      url: "url-to-your-json-file?param=" + inputValue,
    }).done(function(response) {
      console.log(response) //here you deal with the json response
    });