The iOS browser fails to display the image requested via Ajax, even though it has been loaded into the DOM

Update:

  • The issue with the image size does not seem to be the cause, as other photos on my website load without any problems.
  • Upon further investigation, I discovered that this problem only occurs when browsing on iOS. It functions properly on Android devices.

I have developed an infinite scroll plugin to fetch additional posts via REST API in Wordpress. While the plugin operates flawlessly on desktop browsers, it fails to load the images within the posts when accessed through a mobile browser (Tested on Chrome and Safari using my iPhoneX).

After debugging remotely, I identified the following issues:

  • The HTML tag for the image is included in the XHR response.
  • The element corresponding to the image exists in the DOM.
  • No CSS rules like display: none are preventing the image from displaying.
  • The image was received with a status code of 200.

What am I overlooking?

Screenshot from Safari Debugger showing the image response:

Visit my website at: survivalisthk.com (Scroll to the bottom to trigger the infinite scroll feature and witness the image loading issue)

Answer №1

Just figured out the solution on my own. It turns out that the height of the images was being set to 0px when they were loaded. I managed to fix this issue with the code below:

const adjustImageHeight = () => {
    console.log('adjustImageHeight running');
    let images = document.getElementsByTagName('img');
    for( let i = 0; i < images.length; i++){
        images[i].addEventListener('load', function () {
            let naturalHeight = images[i].naturalHeight;
            let naturalWidth = images[i].naturalWidth;
            let newHeight = images[i].width / (naturalWidth / naturalHeight);
            console.log(newHeight);
            images[i].style.height = newHeight + 'px';
            console.log(images[i].style.height);
        });
    }
};

For more information, you can check out: AJAX loaded images not displaying properly in Safari

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

Updating a Mongoose document

I need help with a Node.js and mongoose Module project. I want to find a way to count the number of documents a user has and if they have more than 0 documents, I want to edit their existing document by adding the input text to it. Here is what I have so f ...

What is the best way to use jQuery for uploading files and form data?

How can I upload a file and form data using Jquery in my HTML code? <form id="kayit" action="" method="post" enctype="multipart/form-data"> <input type="text" name="yazi" /> <input type="file" id="resim" name="resim"/> <a onclick="kon ...

Twitter: cease monitoring stream events following X callback

//Just starting out with node.js I'm new to using ntwitter for listening on twitter statuses. Is there a way to stop listening after a certain number of callbacks have been called? var twittsCounter = 0; twit.stream('statuses/filter', { ...

Show the HTML code within the form with the identifier html-editor-form

I have four different sections which are displayed when the corresponding icon is clicked. The area labeled as visual-editor contains multiple HTML values. I am looking to showcase all the HTML values within the visual-editor class under the html-editor ...

JavaScript image sorting function fails to sort multiple ID elements that match

Currently, I am working on a project to develop an image sorter using toggle buttons. However, I have encountered an issue where my function is only effective for the first image ID and not any others. Below is the JavaScript function in question: functi ...

What are some effective ways to test asynchronous functions in React?

Looking for help to test async/Promise based methods in React components. Here is a simple example of a React component with async methods: import server from './server'; class Button extends Component { async handleClick() { if (await ca ...

What is preventing me from applying a jQuery function to an ng-click event in AngularJS?

Seeking clarity on why I am receiving the result of undefined when attempting to construct an ng-click call to a method using a jQuery function. Here's a specific example: <a href="#" class="btn btn-default" ng-click="angularMethod($('input[ ...

Access to XMLHttpRequest has been restricted due to CORS policy when utilizing $.ajax

I attempted to access an endpoint to retrieve a token but encountered an error: Access to XMLHttpRequest at '' from origin 'http:localhost:51780' has been blocked by CORS policy. The response to the preflight request did not pass the ac ...

Guide to configuring a robust schema and validation with joi

Currently in the process of setting up validation using the joi package, encountering syntax-related issues along the way. The schema in place is simple, checking for a valid number and verifying if the ID exists in the database. export default router.pos ...

Focus on the iPad3 model specifically, excluding the iPad4

I am looking to apply specific CSS that works on iPad 3, but not on iPad 4, or vice versa. Currently, I am able to target both versions by using the following code: @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and ( m ...

Troubleshooting nodes in src/http.js using node-inspector for debugging purposes

I've been facing some challenges while debugging a node.js application lately. The issue revolves around needing to set a breakpoint in a file that isn't loaded when the --debug-blk command is executed. Specifically, the file in question is http. ...

Is there anyone who can identify the issues with this form validation?

This is my first time putting together a contact form and I'm encountering some issues. When I click on the submit button, my website doesn't display the PHP page as intended. Additionally, the validation boxes are not showing up when they should ...

Looking for a way to retrieve Instagram data with Python using Selenium, following Instagram's recent API changes? Having trouble locating all entries, as only 12 are showing up?

I am currently working on scraping Instagram using Python and Selenium with the objective of extracting the URL of all posts, number of comments, number of likes, etc. Although I have successfully scraped some data, I have encountered an issue where the p ...

Converting a jQuery $.ajax POST request to a GET request with Django

Is there a way to successfully send a POST request to a Django view without it failing and having to resend as GET? Here is a sample of the code: data = $('#submit_event').serialize() + '&status=new'; $.ajax({ dat ...

Using a regular div to display a modal - Reactstrap

Exploring the possibilities with a Reactstrap Modal: Modal - Reactstrap I am curious about integrating this modal seamlessly into a page layout, similar to a regular div. For example, having the modal display on the page without the animation effects and ...

Storing a URL with a hash and exclamation mark in PHP: Best practices

We are facing an issue with our website that utilizes an AJAX plugin, making it add a #! at the beginning of each page URL. Here's an example of a page URL: Our goal is to retrieve the URL using PHP so we can store it in a meta tag when the page load ...

Retrieving User Activity Reports for a specified set of users within G Suite

I am currently attempting to utilize the Admin SDK Reports Service to retrieve the latest login time and other data for a specific set of 20 users. Due to the large size of the domain, it is not practical to fetch data for the entire domain and then filter ...

Tips on integrating Codrops tutorial codes into a SilverStripe website project

Exploring the vast array of tutorials and code examples on the Codrops site has been an enlightening experience. Codrops Website I'm eager to incorporate some of these resources into my SilverStripe projects as well. SilverStripe CMS After learning h ...

Retrieve particular key from document in MongoDB based on provided value

My Document retrieval process looks like this: async findOne(id: string) { return await this.gameModel.findById(id); } async update(id: string, updateGameDto: UpdateGameDto) { const game = await this.findOne(id) // This code snippet prints al ...

Tips for automating the execution of Chrome extension code on pages with infinite scrolling

Creating my debut Chrome extension, I'm developing a tool to substitute text on web pages. The current code effectively operates on content loaded by DOMContentLoaded. However, when pages employ infinite scrolling and new content is added, the text r ...