简体   繁体   中英

Using $.getJSON for getting json data in pagebeforeshow is not working in jquery mobile

i have used $.getJSON for getting json data on pagebeforeshow but it is not working as it have to.

$(document).on('pagebeforeshow', '#inpGrid', function(e) {
        alert("inpGrid");
        var tat_url = "http://192.168./html5/Demo/json/list.json";

              var url = "http://api.openweathermap.org/data/2.5/forecast?lat=35&lon=139&callback=?" ;
              $.getJSON(tat_url, function(res) {
                  console.log(res)

});

    });

the code is as above, when using url in $.getJSON it is working, wheras as using tat_url it is not working.

the http://192.168./html5/Demo/json/list.json consists as follows

{
    "response": {
        "respCode": 0,
        "output": {
            "delAction": "OP",
            "delTmplt": "sibcVizEdit",
            "title": "List TATs",
            "layout": "grid",
            "srvObjRef": "iawme1/IAWMblztnExpert-ListSIBCs_MB1412577249595",
            "startIndex": "0",
            "recsPerPage": "18",
            "noPages": "1",
            "curPageNo": "1",
            "fieldInfo": [
                {
                    "label": "Name",
                    "type": "STRING"
                }
                {
                    "label": "Alias",
                    "type": "STRING"
                }
                {
              "label": "Datatype",
               "type": "STRING"
                }
                {
            "label": "Default Value",
            "type": "STRING"
                }
                {
             "label": "Visibility",
            "type": "STRING"
                }
            ],
            "records": [
                {
                    "Name": "psngrType"
                    "Alias": "Pasngr Type"
                    "Datatype": "STRING"
                    "Default Value":"CC"
                    "Visibility": "0"
                },
                {
                    "Name": "flightNo"
            "Alias": "Flight No"
            "Datatype": "STRING"
            "Default Value":"$RV_flightNo"
                    "Visibility": "0"
                }
            ],
            "relServices": {
                "AServices": [
                    {
                        "ref": "IAWMblztnExpert-ListSIBCs-UpdateBizContext_MB",
                        "title": "Update SIBC",
                        "desc": "",
                        "srvRef": "IAWMblztnExpert-ListSIBCs-UpdateBizContext_MB",
                        "slctdOffsets": "0"
                    },
                    {
                        "ref": "IAWMblztnExpert-ListSIBCs-ListIICsInSIBC_MB",
                        "title": "List IICs",
                        "desc": "",
                        "srvRef": "IAWMblztnExpert-ListSIBCs-ListIICsInSIBC_MB",
                        "slctdOffsets": "0"
                    },
                    {
                        "ref": "IAWMblztnExpert-ListSIBCs-Deploy SIBC_MB",
                        "title": "Deploy",
                        "desc": "",
                        "srvRef": "IAWMblztnExpert-ListSIBCs-Deploy SIBC_MB",
                        "slctdOffsets": "0"
                    }
                ]
            }
        }
    }
}

Can someone help me please thanks.

Your JSON contain syntax errors, look your ''fieldInfo'' node. You didn't seperate your differents object by ,

Example:

            {
                "label": "Name",
                "type": "STRING"
            },
            {
                "label": "Alias",
                "type": "STRING"
            }

instead of

            {
                "label": "Name",
                "type": "STRING"
            }
            {
                "label": "Alias",
                "type": "STRING"
            }

Use online JSON validator if you need check rest of your json file easily : http://jsonlint.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM