Wouter
Wouter

Reputation: 31

Cordova Phonegap Json Request

I am trying to create an app with phonegap.

When I create a JSON request and run it directly on my webserver it works just fine but in Cordova Phonegap the select field doesn't get filled.

I use the ripple chrome plugin to simulate the app.

What am I doing wrong? any help would be appreciated.

<select class="form-control  dealsearchselect" id='com' style='height: 50px; width: 100%;'>

</select>


<script>
$( document ).ready(function() {
  let dropdown = $('#com');

  dropdown.empty();

  dropdown.append('<option selected="true" disabled>Selecteer</option>');
  dropdown.prop('selectedIndex', 0);

  const url = 'https://url/com_json.php';

  // Populate dropdown with list of provinces
  $.getJSON(url, function (data) {
    $.each(data, function (key, entry) {
      dropdown.append($('<option></option>').attr('value', entry.id).text(entry.name));
    })
  });

});

</script>

This is the data provided from JSON

[
  {
    "id":"52",
    "name":"Huishouden, Gezin en Dier"
  },
  {
    "id":"20",
    "name":"Dienstverlening"
  },
  {
    "id":"29",
    "name":"Kleine reparaties"
  },
  {
    "id":"62",
    "name":"Training en Educatie"
  },
  {
    "id":"1",
    "name":"Huis en Tuin"
  },
  {
    "id":"73",
    "name":"Artistiek"
  },
  {
    "id":"77",
    "name":"Amusement en Workshops"
  },
  {
    "id":"43",
    "name":"Auto en Vervoer"
  },
  {
    "id":"86",
    "name":"Welzijn en Verzorging"
  }
]

Upvotes: 2

Views: 68

Answers (1)

andreszs
andreszs

Reputation: 2956

Have you added the content security policy meta tag to the head section of your index.html file to allow unsafe inline Javascript execution? Try this one:

<meta http-equiv="Content-Security-Policy" content="connect-src *; default-src * 'self' 'unsafe-inline' 'unsafe-eval' gap: data: ms-appdata: blob: file:; style-src 'self' 'unsafe-inline'; media-src *" />

Also, why don't you run and debug the app on the device directly to see the errors in real time? You can easily debug the app on devices using Visual Studio 2017.

Upvotes: 1

Related Questions