Image failed to load

Issue Encountered in Browser Console:

 https://static.food2fork.com/pastaallavodkaa870.jpg.jpg 404

While attempting to display the image on the browser, I am uncertain if the problem lies within my code or with food2fork.

Code from index.js:

// Always ensure correct directory

// Import necessary fields 
import Search from './models/Search'; 
// Import all functions from the view 
import * as searchView from './views/searchView'
import {elements} from './views/base'; 

/* Global state of the application
    - Search object 
    - Current recipe object
    - Shopping list object
    - Liked recipes
*/

// Empty state each time the app is reloaded 
const state = {}
const controlSearch = async () =>{
    // 1) Retrieve query from the view 
    const query =  searchView.getInput();

    if(query){
        // 2) Create new search object and add it to state 
        state.search = new Search(query); // New instance of the search class 

        // 3) Prepare UI for results 

        // 4) Search for recipes 
        await state.search.getResults(); // Await this promise then render the result 

        // 5) Render result in the UI, remember to hit the search button 
        searchView.renderResult(state.search.result);

    }
}
elements.searchForm.addEventListener('submit', e => {
    e.preventDefault();
    controlSearch();
});

Content from Search.js:

// This comes from an external source, simply call its name
import axios from 'axios';

// Query followed by search result 
// Class declaration in ES6
export default class Search { 
    constructor(query){
        this.query = query;
    }

    async getResults(){
        // Fetch will only work with modern browsers 
        // HTTP request using axios 
        // If invalid key entered, it will not work
// Key has been blurred out for privacy reasons
        const key = '------------------------';

        // Return JSON 
        // Use a CORS proxy if unable to access directly
       // Proxy can be found through Google search
        try{
            const res = await axios(`https://www.food2fork.com/api/search?key=${key}&q=${this.query}`);
            this.result = res.data.recipes;
            // console.log(this.result);
        } catch(error){
            alert(error);
        }
    }


}

For searchView.js:

// When in current folder, it's just base 
import {elements} from './base'; 
// Return input value from field 
// Implicit search returns automatically 
export const getInput = () => elements.searchInput.value; 

const renderRecipe = recipe =>{
    const markup = `
        <li>
            <a class="results__link" href="#${recipe.recipe_id}">
                <figure class="results__fig">
                    <img src="${recipe.image_url}.jpg" alt=${recipe.title}>
                </figure>
                <div class="results__data">
                    <h4 class="results__name">${recipe.title}</h4>
                    <p class="results__author">${recipe.publisher}</p>
                </div>
             </a>
        </li>
    `;
    // Insert HTML
    elements.searchResList.insertAdjacentHTML('beforeend',markup);

}

export const renderResult = recipes => {
    recipes.forEach(renderRecipe);
}

From base.js:

// All DOM elements stored here as objects
export const elements = {
    searchForm: document.querySelector('.search'),
    searchInput: document.querySelector('.search__field'),
    searchResList: document.querySelector('.results__list')
}

I am relatively new to web development and self-learning. Hopefully this is not considered a poor question. Seeking assistance from experienced individuals to pinpoint any errors, as it appears to not be related to syntax or logic. Thank you very much and have a wonderful day.

Answer №1

https://static.food2fork.com/spaghetticarbonara123.jpg
Do you want to keep the image extension as .jpg? If not, please remove it.

https://static.food2fork.com/spaghetticarbonara123.jpg

Answer №2

To make it function properly, all you have to do is delete the extra .jpg.

https://static.food2fork.com/pastaallavodkaa870.jpg

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

The issue arises with the Google Map marker failing to function correctly when pulling data

I've recently started learning Google Maps. It's interesting that markers work and are displayed when statically declared, but not when retrieved from a database. // var markers = [[15.054419, 120.664785, 'Device1'], [15.048203, 120.69 ...

Unable to insert HTML code into a div upon clicking an image button

I am in the process of developing a website dedicated to radio streams, and I was advised to utilize Jquery and AJAX for loading HTML files into a div upon button click. This way, users wouldn't have to load an entirely new page for each radio stream. ...

Arranging nested arrays

There is a nested list provided with the following markup (which cannot be altered currently). My goal is to sort this list and all nested lists by the title of the 'a' tag. The initial div (not nested in 'li') should be used for sortin ...

Pair of Javascript Functions Using Async with Parameters

This question builds upon a previous inquiry raised on Stack Overflow: When considering approach number 3 (referred to as the "counter" method), how can we ensure that the function handleCompletion can access necessary data from startOtherAsync to perform ...

The update feature seems to be malfunctioning within the MEAN Stack environment, specifically with node.js and angular js

Looking for some assistance as a beginner in the mean stack. I'm trying to update a record using the update function, but it's not working as expected. I need to update a specific object based on its ID, however, I'm encountering issues wit ...

Repeating X and Y Axis Labels on Highcharts

Highchart is new to me. I recently created a basic chart showing the count of males and females over the past five years. I have included a screenshot for reference. I am wondering if it's possible to remove duplicate labels from both axes? Below is ...

How can images from a dynamic table be converted to base64 format in Vue.js and then sent in a JSON file?

Hello everyone, I'm facing an issue with a dynamic table where I need to add multiple rows, each containing a different image. I attempted to convert these images to base64 format and save them in a JSON file along with the table data. However, the pr ...

A step-by-step guide on leveraging ethereumjs-tx within a web browser

Is it necessary to install npm ethereumjs-tx when utilizing the browser-based version downloaded directly from GitHub? If so, how can we incorporate the ethereumjs-tx module into our script file? It seems like these are two separate components based on ...

Contradictory jQuery extensions

After exploring this site as part of my web coding self-study, I decided to register so I could ask a specific question. Currently, I am in the process of developing my new website and ran into an issue on a test page (www.owenprescott.com/home.html). The ...

The FullCalendar VDOM has been successfully loaded

After loading Full Calendar version 5.5.1, I encountered the error message "FullCalendar VDOM already loaded." Despite searching online, I was unable to find a suitable solution for this issue. I am utilizing NPM as my web pack build system for this proj ...

Issue encountered with Fabric js: Unable to apply pattern fill to a group of rectangles

Greetings, I am in need of some assistance with a coding issue. I have a for loop that generates and adds multiple rectangles to a fabric js canvas. To set a texture for each rectangle, I am using the following code snippet. var rect = new fabric.Rect( ...

"Implementing a method to update an object by its Id within a nested array that includes children, and then managing the state in

How can I dynamically toggle the isExpanded property on click based on an element's ID in a React project? Below is the JSON data structure I am working with const handleExpandOutlineItem = (id: string) => {} This is the structure of my JSON data: ...

Why is my Angular 2 service not showing up in my application?

Trying to access a JSON file using an Angular service has been unsuccessful. While I can easily read and bind the JSON data without the service, attempting to do so with the service results in an error message: Failed to load resource: the server responde ...

When you make a POST request to an express API, the properties are not clearly defined

Just getting into Vue.JS and experimenting with creating a basic MEVN to-do list app for practice. I keep encountering an issue when trying to send a POST request to my express server, receiving the error message: TypeError: Cannot read properties of unde ...

Expanding Vue JS Vuetify Panels in a V-for Loop to Reveal Multiple Panels

When pulling data from a database and looping through it in the DOM using a "v-for" loop, I encountered an issue with Vuetify expansion panel components. The problem is that when a user clicks to open one expansion panel, it ends up opening all other panel ...

The networking feature stops functioning on Android devices after upgrading from Ionic 1.5.0 to 1.6.3

After upgrading from ionic 1.5.0 to 1.6.3 (the latest version), I noticed that networking ajax calls were no longer working on Android. I had to remove and re-add the android platform, and there seemed to be a change in the apk names from MainActivity-debu ...

React JS - Cautionary Messages Encountered During Execution of the npm add gh-pages Command

I attempted to integrate gh-pages into my project, but unfortunately encountered some warnings that prevented me from completing the process successfully. Feel free to view the image link below for more information ...

Tips on modifying the content of a Material UI Card

I have a Material UI card displaying some details, along with an 'Edit' button. When the Edit button is clicked, I want to update the content of the card within the same layout. Below is the code snippet: <Card className={classes.root} variant ...

Customizing ExtJS 4.1: Mastering field overrides

Seeking guidance on applying a plugin to all fields(numberfield, textfield, datefield, etc.) within the ExtJS 4.1 library. Does anyone have suggestions on how to achieve this? I understand that all fields are derived from BaseField. I attempted the follow ...

swap out the CSS class for my own class dynamically

When I display HTML code like this <div class="btn btn-pagination"> <i class="fa fa-angle-right"></i> </div> and want to replace fa fa-angle-right with myClass when the page loads. I attempted: $(document).ready(function () { ...