jqueryioscordovaappframework

Local data doesn't load in phonegap build + appframework app


I'm developning an App framework + phonegap build application for ios. When a panel with id #item1 loads I wan't to fetch data localy and write it to the page. I use this:

   $('#item1').on("loadpanel", function(){



            $.ajax({
                type:"GET",
                url:"data/mydata.json",
                contentType:"application/json",
                success:function(data){



                    console.log(data.cat);

                    alert(data.cat);

                    $.ui.setTitle(data.cat);


                    $.each(data.entries, function( index, value ) {

                        $('ul.list').append('<li data-filter="' + value.title + '"><a href="#details/'+ index +'/1">' + value.title + '</a></li>')

                    });


                    $(".list").filterList();

                },


                error: function (xhr, ajaxOptions, thrownError) {
                    alert("errorstatus: " + xhr.status + " ajaxoptions: " + ajaxOptions + " throwError: " + thrownError);

                }



            });


        }); 

This works just fine in the browser, but when I package the app for ios using phonegap build, nothing gets appended to the page and the alert statement says undefined. This might be related to the phonegap access tag in config.xml, so I'll paste them in here aswell:

    <access origin="*" />
 <access origin="*"/>

All help much appreciated!


Solution

  • dataType (default: Intelligent Guess (xml, json, script, or html)) Type: String The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string). The available types (and the result passed as the first argument to your success callback) are:

    "xml": Returns a XML document that can be processed via jQuery.

    so you need to set

    dataType:"json"

    refer

    otherwise use $.getJSON