Tips for loading internal JSON data using $http.get instead of using an external JSON file

I am currently facing an issue where I use a code snippet to load strings from an external json-file. While everything works fine, running the function locally triggers a 'cross origin' problem. As a solution, I attempted to input the strings directly into my JS file, but unfortunately, it did not work.

Original JS

$scope.loadAutosuggest = function(query) {
    return $http.get('data.json');
};

data.json

[
    "In Progress: Yes",
    "In Progress: No"
]

I have tried implementing this alternative approach (which also did not work)

$scope.loadAutosuggest = [
 "In Progress: Yes",
 "In Progress: No"          
];

If you have any advice or tips for me on how to resolve this issue, I would greatly appreciate it. Thank you.

Answer №1

One issue could be that the variable $scope.loadAutosuggest is supposed to be a function.

$scope.loadAutosuggest = function() {
  return [
    "Completed: Yes",
    "Completed: No"          
  ];
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using the 'gf' command in Vim to resolve JavaScript modules with a Webpack tilde alias

Recently, I joined a Vue.js project that makes use of the tilde (~) notation in module imports. For example: import WhateverApi from '~/api/whatever'; The project repository is a mix of various files including a Vagrant machine setup, a Laravel ...

Steps to refresh a variable when the SMS read plugin successfully completes

I'm attempting to make a post call within the success callback of my SMS read plugin code. I can successfully print _this.otpnumber in the console. Please refer to my stack trace image link getSMS(){ var _this= this; var fil ...

What is the most effective way to update the React state based on an if-else condition within a

I am facing an issue where I have a component in my project that needs to update the parent state when clicked, but there is an if-else condition causing the state not to update in the parent component. In my project, I have two boxes with an if-else cond ...

Using React to access the properties of objects within an array that has been dynamically mapped

For my initial dive into developing a React application, I am currently in the process of fetching data from a database and updating the state to store this information as an array. My main challenge lies in accessing the properties of the objects within t ...

An alternative way to show time zones such as PT and ET instead of using PST and EST with the help of moment

For efficiency in table space using moment.js, I am looking to utilize PT/ET instead of PST/EST. HTML- {{ moment.tz([2012,0],timezone).format('z')}} // It displaying EST/PST but I need only ET/PT. Note: The timezone is dynamic, so regardless of ...

I am attempting to load the ajax content into separate divs simultaneously

When I attempt to load the ajax into two separate divs, I notice that despite calling for data to be placed in two different divs within the ajax code, it all ends up in one div. <script>$(document).ready(function(){ $.ajax({ url: "http: ...

Adding information into a separate row via JavaScript

When using XMLHttpRequest to retrieve data from a custom URL, specifically mocki.io and fake JSON, I am encountering an issue where all data elements (element.name and element.city) are being placed in one table row. Ideally, I would like each pair of name ...

Improving the implementation of in-memory caching in javascript/nodejs

One thing that comes to mind is the issue of memory leaks. Consider this code snippet: let inMemoryCache = {}; app.get("/hello",(req, resp) => { inMemoryCache[unixTimeStamp] = {"foo":"bar"} resp.json({}); }); It&apo ...

The useAutocomplete function in Material-UI fails to consider the disabled

Currently, I am working on developing my own Autocomplete component by utilizing the useAutocomplete hook from the mui/base package. Most parts of the implementation are functioning correctly, except for the disabled option. My expectation is that the com ...

What is the process for extracting data from latitude and longitude in order to generate a marker on Google Maps using a script

I have an HTML input text and want to pass coordinates to create a marker on Google maps. Check out the code here: jsfiddle.net/#&togetherjs=r3M9Kp7ff7 What is the best way to transfer this data from HTML to JavaScript? <label for="latitude">L ...

Why is My TensorFlow.js Model for Predicting 2 Table Multiples Not Producing Accurate Results?

I have created a tensorflow.js model that predicts outputs in multiples of two. For example, if the input is 16, the prediction should be 32. However, even after providing the input data and labels accordingly, the output printed is [[1],] after prediction ...

Validating dropdown lists with Jquery

Custom Dropdownlist: <div class="col-md-2"> <div class="form-group"> <label for="field-3" class="control-label">Priority</label> <select id="lstpriority" class="custom-selectpicker" data-live-search="true" da ...

A guide on successfully transferring JSON Data to an Express REST API

Currently, I am in the process of developing a REST API with Node/Express and have a query regarding the setup of the API along with integrating a JSON file. As an illustration, the JSON data that I wish to reference consists of an ID number, model, and co ...

An error was encountered: object does not possess the function 'tooltip'

I have been attempting to display a tooltip on a textbox using jQuery scripts within a web form that utilizes a Master Page. While everything appears to be working fine when I run my code, I am encountering the above error in the resources folder of the DO ...

Implementing a click event on a selection option – tips and tricks

When I want to select an option, I can use the following script: Javascript $("#practice-area optgroup option").click(function(){ // insert your function here }); HTML <select name="practice-area" id="practice-area"> <option value="0">S ...

Setting up internationalization (i18n) in JavaScript

I am in the process of creating a dynamic webpage using i18n's JavaScript library. I have been following their example code from their homepage located at: However, I am encountering difficulties in loading the specified JSON data, despite adhering t ...

iPad problem resolved: Disable click hover and double-click issue

I'm experiencing a problem with my web application specifically on Safari for iPad. I have to click twice in order to actually perform the click on the <a> tag. The first click triggers a hover effect, similar to when you hover with a mouse on d ...

Import a JavaScript file with beneficial test functions for selenium testing

Utilizing the runScript command in selenium has proven to be incredibly helpful for me. I've been using it to calculate values within a table and then store the result like so: <tr> <td>runScript</td> <td>var cumulativ ...

Fluctuating Value Assignments in Node.js

UPDATE: I have simplified the sample code for better understanding. I couldn't find any solution to my problem while searching online. I have a function that acts as a wrapper for simplecrawler. Here is the modified code: const Crawler = require(&ap ...

Tally the values entered into the text input field

I am interested in counting the number of IDs within an input of type "text" The values return like this: 1, 4, 6, etc. <input type="hidden" class="selected_ids" value="selected_ids" name="selected_ids[]" multiple="yes" id="selected_ids" /> ...