Error: jsonFlickrFeed has not been declared

My request is as follows:

const flickrApiPoint = "https://api.flickr.com/services/feeds/photos_public.gne";

try {

  $.ajax({
    url: flickrApiPoint,
    dataType: 'jsonp',
    data: { "format": "json" },
    success: function (data) {
      console.log(data); //formatted JSON data
    }
  });
}
catch (e) {
  console.log(e);
}

However, I am encountering the following error:

Uncaught ReferenceError: jsonFlickrFeed is not defined
    at photos_public.gne?&callback=jQuery331016421245174669186_1523107884637&format=json&_=1523107884638:1

Can someone please point out what I am doing wrong and how I can fix it? Thanks in advance!

Answer №1

Your linkflickrApiPoint seems to be missing some important details. Make sure it is set to

const flickrApiPoint = "https://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";

Here's a complete example:

const flickrApiPoint = "https://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";

    try {

          $.ajax({
            url: flickrApiPoint,
            dataType: 'jsonp',
            data: {format: "json"},
            success: function (data) {
              console.log(data); // JSON data
            }
      });
    }
    catch (e) {
      console.log(e);
    }

Answer №2

When utilizing a jsonp ajax call, the flickr services responds with a call to the function: jsonFlickrFeed. In order to handle this, you have to define such a function in your code:

function jsonFlickrFeed(json) {
    console.log(json);

    $.each(json.items, function (i, item) {
        $("<img />").attr("src", item.media.m).appendTo("#images");
    });
}

This function will be executed automatically upon completion of the ajax call. Therefore, instead of using the traditional success callback in your ajax request, you should define a jsonFlickrFeed function callback.

function jsonFlickrFeed(json) {
    //console.log(json);
    console.log('jsonFlickrFeed called');

    $.each(json.items, function (i, item) {
        $("<img />").attr("src", item.media.m).appendTo("#images");
    });
}
const flickrApiPoint = "https://api.flickr.com/services/feeds/photos_public.gne";

try {

    $.ajax({
        url: flickrApiPoint,
        dataType: 'jsonp',
        data: { "format": "json" },
        complete: function (data) {
            console.log('ajax call completed'); //formatted JSON data
        }
    });
}
catch (e) {
    console.log(e);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<div id="images"></div>

Answer №3

Ensure you add the parameter nojsoncallback=1 in order to exclusively retrieve a JSON object.

const flickrApiPoint = "https://api.flickr.com/services/feeds/photos_public.gne?nojsoncallback=1";

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

Retrieve GPS data source details using Angular 2

In my Angular 2 application, I am looking to access the GPS location of the device. While I am aware that I can utilize window.geolocation.watchposition() to receive updates on the GPS position, I need a way to distinguish the source of this information. ...

Is there a way to enable access to the BTable properties beyond the table itself?

I am in need of a way to close the details of one row from another row. My current strategy involves using the index number of each row to check the value of showdetails. However, I have not been successful in accessing one row object from within another. ...

The alert message fails to appear during an Ajax request

I'm having trouble understanding why the Ajax function in this code snippet is not triggering the success or error functions: function get_cust_key(custid) { $.ajax({ type: "POST", url: 'http://localhost/Test/index.php/getCust ...

Tips for using a button to update data without triggering a postback

Within the GridView in my ASP.net project, I have an ASP.net button with the following code: <asp:Button UseSubmitBehavior="false" runat="server" ID="btnShow" CssClass="btnSearch" Text="View All" CommandName="ViewAll" OnCommand="btnShow_Command" Comman ...

Guide on inserting text input value into the href attribute of a hyperlink

Lately, I've been facing an issue that has been troubling me for the past few hours. I have a search input field where users can enter text and click send. The entered text should then be added to the href attribute and sent to the results page for qu ...

Transferring an Array of Objects to a Vue.js Component

I'm just starting out in web development and experimenting with creating a front end using vuejs and vuetify. I've encountered an issue where I can't seem to pass an array of objects to a component. Here is the code snippet: In my main pag ...

"Troubleshooting async/await issue with Node.js Sequelize and configuring the connection

function credential(secretFromVault) { const creddetails = new ClientSecretCredential(clientId, tenantId, clientSecret); // Build the URL to reach your key vault const url = `https://<vaultName>.vault.azure.net/`; // Lastly, create our secre ...

Error when compiling TypeScript: The callback function provided in Array.map is not callable

This is a Node.js API that has been written in Typescript. app.post('/photos/upload', upload.array('photos', 12), async (req, res) => { var response = { } var list = [] try { const col = await loadCollection(COLLECTION_NAM ...

Personalize the "set up notification" PWA on React

Is it possible to customize this default design, including the picture, title, description, and background? I made changes in manifest.json, but nothing seems to have happened. Here is a picture of the random install prompt that I would like to customize ...

The issue with properly filtering a nested JSON object within an array in JavaScript

I am currently working on integrating a search input filter inside a dropdown menu that contains nested dropdown list items. The JSON data I receive from the API response is as follows: API response glPlmAsmt.category = { "page_size": 100, ...

Having trouble with the Jquery click event not functioning on an interactive image map in Chrome browser

I currently have an interactive image-map embedded on my website. Here is the HTML code: <div id="italy-map" class="affiancato verticalmenteAllineato"> <div id="region-map"> <img src="./Immagini/transparent.gif" title="Click on ...

ZK: maintaining session connectivity

When I need to redirect to a tel:**** link in ZK and then redirect the user to another page after the call, I encounter a problem. Every time I click on the link, ZK interprets it as leaving the browser, which results in my client session ending automatica ...

Managing data retrieval in React using the OpenWeather API

I'm currently working on a React app as part of my learning journey. I'm facing an issue with rendering the data object correctly in my component. I tried using day.key to access the information I need to display, but it's not working as exp ...

Firebase: Linking a child key from table to another table

Just started working with firebase database and I could use some assistance with mapping to two tables. I have two tables, robots and templates. The template key is assigned to a child node under the robots table. View tables In the robots table, I would ...

Improving React Components with Material-UI Integration

Is it possible to export a class extended from React.Component while using React and Material-UI? I need to access React variables like state within the class. If exporting the extended class is not an option, how can I still utilize state? Here is a samp ...

Improving form handling with Vuex: Ensuring state is only updated after pressing the submit button

I am currently working on developing a form that pulls data from a Vuex store, allowing users to update the form fields and then submit when they are ready. Most tutorials I have seen use v-model with computed get() and set() to retrieve values from the s ...

How to prevent jQuery from continually recalculating width on window resize?

Here is the code I've been working on: http://jsfiddle.net/7cXZj/ var callback = function () { $('.progress-bar').width($('.progress-bar').parent().width() - 190); $(".mainpart-background").animate({ width: "80%" }, 80 ...

Validating forms using Ajax in the Model-View-Controller

I am facing an issue with my Ajax form, where I need to trigger a JavaScript function on failure. The code snippet looks like this: using (Ajax.BeginForm("UpdateStages", new AjaxOptions { HttpMethod = "POST", OnSuccess = "refreshSearchResults(&apo ...

Tips for loading nested JSON data into an Angular Material dropdown list

My task involves extracting data from a JSON object and displaying the difficultyLevel. Despite several attempts, I have been unable to achieve the desired outcome. What changes should be made to the HTML file? const ELEMENT_DATA: data = { questions ...

Building conditionals in AngularJS expressions using if-then-else syntax

Is there a way to incorporate the ternary-operator (if-then-else construction) in an angularjs expression? For example, I have a function $scope.isExists(item) that should return a boolean value. I would like to do something like this: <div ng-repeater ...