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

What is the reason for the initial DOM operation taking significantly longer than subsequent ones?

Why is the first operation much more despite the subsequent manipulation of the DOM being practically identical in time when both are written with the realization in JS and jQuery? Link to Javascript source // ES5 // Sending a message function sendMessa ...

What is the process for triggering data-dismiss after the href has been activated?

Could someone help me with this issue? <a class='btn btn-danger' href='page.html'>Delete</a> I am trying to activate the "data-dismiss" attribute after the "href" is activated. My initial attempt was using this code: < ...

personalizing jquery templates

Currently, I am utilizing a jQuery template to showcase specific values. Within this template, I have included an if statement to determine if the age is considered old or not, with the result altering the background color accordingly. Previously, the co ...

Differences in HTML animations can be seen when comparing Google Chrome to Microsoft Edge. Looking for a workaround for autoplay to ensure

My intro video animation is facing recording difficulties due to the autoplay policy in Google Chrome. It seems nearly impossible to capture it accurately. If only autoplay could function for an offline HTML file, my issue would be resolved. Unfortunately ...

Determine using Javascript or jQuery whether the value of input1 is greater than the value of input2

Ensuring that Value1 is always greater than Value2 in a form submission is crucial. If Value1 becomes greater than or equal to Value2, an error message should be displayed and the form submission should not be processed. Below is the code for the form: & ...

Creating and writing content within files and directories dynamically using Node.js for a starter kit generator

My goal is to develop a Project Starter Kit Generator for a framework similar to Angular CLI using node.js. If I were to use the command kit-cli, the necessary features would include: kit-cli init or kit-cli am/as: This command will prompt users with ...

Unable to utilize navigator.camera.getPicture in iOS while using PhoneGap Adobe Build

I've spent hours searching, trying to troubleshoot my PhoneGap app (compiled by Adobe PhoneGap Build) and I suspect there's something crucial about PhoneGap that I'm missing. I've added the following lines to the config.xml file: <f ...

What is the best way to fill in fields on my webpage using a dropdown menu choice?

I'm exploring the world of ASP.NET MVC, AJAX, and jQuery for the first time. I'm attempting to populate some text boxes on my website based on a dropdown selection but it seems like the data isn't getting through. I suspect that the 'ch ...

Incorporating SCSS directly in React component along with material-ui styling

I'm having trouble incorporating styles into my React component. I'd prefer to use SCSS instead of either using the withStyle function or importing a plain CSS file into a JS file. For instance, I would like to import my SCSS file into ButtonCom ...

Save an array of messages by making separate API calls for each one

I have a function that makes an API call to retrieve a list of message IDs. Here is the code: function getMessageList(auth) { api.users.messages.list({ auth: auth, userId: 'me', }, function(err, response) { if (er ...

Issue with Material UI Textfield error functionality in React.js not functioning correctly

Currently, I am working on a functional component in combination with Material UI. Within this setup, I have constructed a form comprising of 2 textfields. My objective is to activate the error property solely under certain conditions being met. However, t ...

Determine if a specific value is present in an array of objects using AngularJS

var arr = [ { id:1}, {id:2} ]; var obj = {id:1}; var result = arr.indexOf(obj.id) == -1; console.log(result); I am trying to determine if obj.id exists in the array arr[]. Please note: arr[] is an array of objects ...

What is the reason that setState functions properly when parsing each key separately, but fails when passed as an object?

Currently, I am delving into the world of React and TypeScript, but I have encountered a problem when trying to pass an object with a specific type in order to update the state. For some reason, the state remains unchanged. My approach involves using the ...

How does the Cluster module in Node.js compare to the Cluster module in Learnboost?

Node.js features its own Cluster core module (source: http://nodejs.org/docs/v0.8.3/api/cluster.html) while Learnboost has introduced a similarly named Cluster module as well (source: , https://github.com/LearnBoost/cluster). What are the differences betw ...

Display two elements within a single table column by utilizing an array in Vue.js

I have a requirement to display 2 items from an array in one table TD ( column ). Below is the example mock data provided: agendas: [ [ { tag: 'p', class: 'm-agenda__date', value: & ...

Share your ES module (.mjs) on NPMJS with support for Node versions older than 8.5.0 (Dual Package)

In the past, publishing a module written in ES6 to NPMJS was a simple process: transpile the code using Babel and publish the resulting `lib` directory to NPMJS while keeping the original `src` files on GitHub. However, with Node v8.5.0's experimenta ...

Access the information from the text box and text area, then store it into a cookie using either jQuery or JavaScript

I need to save the text entered in a textbox within an iframe. How can I achieve this using jQuery or JavaScript? Any assistance would be greatly appreciated. ...

Using async-await to handle an array of promises with the map method

I have come across several discussions on the same error but none of them solved my issue. Here is the code I wrote: const userOrganizationGroups = (organizationGroupsList) => { if (Array.isArray(organizationGroupsList) && organizationGroupsLi ...

Understanding Mongodb: the process of populating a schema that is referenced within another schema using an API

Looking to make adjustments to my Api in order to populate a referenced schema. Here's the schema I am working with: export const taskSchema = new Schema ({ user:{ type: String, required: true }, project: { type ...

jQuery is failing to properly render dynamic content data identifiers

Need help with a dynamic HTML div <a data-id="17" onclick="getcustomer();"> <div class="note note-success"> <h4 class="block">A</h4> <p>Email : <a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...