I have a project that uses jQuery, and I have a lot of functions that return json, and I am trying to populate a data variable with some test data but when I loop through the data I am getting nothing.
I have checked to make sure that my ajax call is returning the json data and it is, and I am kind of at a loss on why nothing is being returned
<div id="app">
<template v-for="person in persons">
<div>
{{ person.FirstName }}
</div>
</template>
</div>
<script>
new Vue({
el: '#app',
created: function () {
this.GetUserDetails();
},
data: {
persons: []
},
methods: {
GetUserDetails() {
this.persons = CommonFunctions.GetJSON("Person");
}
}
});
</script>
Here is some of the Person json,
[{
"id": 1,
"FirstName": "Auroora",
"LastName": "Kosel",
"gender": "Female"
},
{
"id": 2,
"FirstName": "Nevins",
"LastName": "Rulf",
"gender": "Male"
},
{
"id": 3,
"FirstName": "Silvana",
"LastName": "Cragoe",
"gender": "Female"
}]
** EDIT ** Here is the GetJSON function
var CommonFunctions = {
GetJSON: (whichOne) => {
$.ajax({
type: "GET",
url: "../Scripts/" + whichOne + "JSON.json",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
return data;
}
});
}
}
console.log(this.persons)inGetUserDetails, do you get proper value?CommonFunctions.GetJSONfunction?