The screen isn't displaying the result after making an ajax call

As I work on developing a photo sharing website with a layout similar to Pinterest, I am facing an issue. When I click on a category in the menu, the old content disappears but the new content does not show up. Interestingly, upon inspecting the elements using Chrome browser, I can see that the fetched contents are there.

I'm puzzled as to why the fetched content is not appearing in the specified div on the webpage.

Below is a snippet of the HTML code:

<div id="container">
    <div class="main" id="main">
        <ul id="tiles">
            <li><img src="asd/12994.jpeg" /></li>
            <li><img src="asd/12995.jpeg" /></li>
            .
            .
            .
        </ul>
    </div>
</div>

To address this issue, I have implemented an ajax function to replace all contents within the div with the id "main". Here's the relevant ajax code:

$.ajax({
    type:'POST',
    url:'strip_all.php',
    data: 'asa='+aq,
    cache:false,
    success:function(res) {
        $('#cat_on_oven_popping').css('display','none');
        $('#main').html(res);
    }
});

Answer №1

It seems like there is something causing your data to be hidden with the display: none; attribute.

Unfortunately, based on the code you provided and the fact that #cat_on_oven_popping is not involved, it's hard to pinpoint the exact cause.

I recommend using Dev Tools to identify which property is setting this attribute and then investigate how it is being added.

(You could also try removing

$('#cat_on_oven_popping').css('display', 'none')
temporarily to see if that changes anything)

Answer №2

Make sure to catch any errors:

$.ajax({
    type:'POST',
    url:'strip_all.php',
    data: 'asa='+aq,
    cache:false,
    success:function(res){
         $('#cat_on_oven_popping').css('display','none');
         $('#main').html(res);
    },
    error: function () {
            console.log(arguments);
    }
});

Have you encountered an error?

Note: It's recommended to send JSON to the "data" parameter like this:

$.ajax({
    type:'POST',
    url:'strip_all.php',
    data: {
       'asa':aq
    },
    cache:false,
    success:function(res){
         $('#cat_on_oven_popping').css('display','none');
         $('#main').html(res);
    },
    error: function () {
            console.log(arguments);
    }
});

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

Angular Igx-calendar User Interface Component

I need assistance with implementing a form that includes a calendar for users to select specific dates. Below is the code snippet: Here is the HTML component file (about.component.html): <form [formGroup]="angForm" class="form-element"> <d ...

JSON data is used to dynamically render tables in this process

I have a challenging requirement and I am in search of a dynamic solution to render it. I am reaching out to the experts for assistance with the following requirement. https://i.sstatic.net/VLBd5.jpg I am looking to display the data in the format shown a ...

Replace the term "controlled" with "unleashed" when utilizing the file type input

In my app, I have defined multiple states like this: const [state,setstate]=React.useState({headerpic:'',Headerfontfamily:'',Subheaderfontfamilty:''}) And to get an image from my device, I am using the following input: &l ...

Having difficulty altering the font in the WordPress tinymce editor

I've been attempting to update the font in the WordPress tinymce editor, but I'm running into issues. First, I created a tinymce-custom-editor.css file with the following code: @import url(https://fonts.googleapis.com/css?family=Open+Sans:400,7 ...

Exploring the components of the scene with three.js

I have a desire to explore each element within a particular scene. These elements come in various forms such as THREE.Object3D, THREE.Mesh, and more. Some of these elements contain a property called children, which is essentially an array of other elements ...

Unique alphanumeric code following the inclusion of a JavaScript file

I'm encountering an issue with a webpage that incorporates two JavaScript files. When inspecting it using firebug, I noticed that every time the page loads, these two files are included with the prefix ?_=someRandomNumber I'm unsure about the or ...

What causes the element to load with a transparent appearance? And why is my JavaScript code overriding the hover effect on it?

My goal is to have an element fade out when clicked and then fade back in when its space is clicked again. I also want the opacity of the element to be 0.9 instead of 1 when visible. I've encountered two issues with my code. First, the hover selector ...

What is the best way to add an element directly following another within the document's head section?

In my HTML project, I am using JavaScript to insert style elements into the head section. I have implemented a function that should inject styles into a specific id within the head tags. This is a snippet of my current HTML code: function insertAtElemen ...

Using Vue with Firebase to fetch a specific range of data starting from a particular record and ending at the

I am looking to retrieve all records from a certain record to the very last one in my database. ref.orderByChild("date").equalTo("19/11/2020 @ 19:50:29").on("child_added", (snapshot) => { console.log(snapshot.va ...

Is there anything I can modify in either the HTML or CSS code to achieve the desktop layout I envisioned?

I have been striving to replicate this https://i.sstatic.net/B0Qkb.jpg desktop design. The mobile version has already been crafted, but when I attempt to adapt it for desktop, I'm utilizing a specific flex property called row-reverse. However, the ou ...

Ways to terminate session using ajax when input is empty; Notice of an undefined variable

Warning: Variable 'outputname' is undefined There is a query in the file memberSearch.php. I want to echo the $outputname variable in another PHP file inside an input tag. However, when I try to echo ($outputname) in another file, it returns an ...

Creating flex items that mimic the fluidity of text

Is there a way to achieve fluid text behavior for flex items like in the following example: .container{ display: flex; flex-wrap: wrap; max-width: 200px; background: red; } div:not(.container){ w ...

Double the Trouble: jQuery AJAX Making Two Calls

I've already posted a question about this, but I have now identified the exact issue. Now, I am seeking a solution for it :) Below is my code snippet: $('input[type="text"][name="appLink"]').unbind('keyup').unbind('ajax&apos ...

What could be the reason behind the discrepancy in functionality between two identical jsfiddles?

I am currently in the process of trying to create a map where each subsection will highlight when hovered over. After conducting some research, I came across imagemapster as the recommended method to achieve this functionality. Surprisingly, the first link ...

Exploring the Enzyme library in React to trigger an onClick event with a specific parameter

In my quest to simulate an onClick method in my unit tests using Enzyme for React, I have encountered various tutorials on simulating an onClick event that takes an event e. For example: handleClick(e) { // Does something } .... <MyComponent onCli ...

jquery dialog content vanishing upon second opening

My jQuery code is set up to display a dialog when a button is clicked. The issue I'm experiencing is that after closing the dialog and reopening it, the text area within the dialog appears empty with only three buttons visible. However, upon subsequen ...

Collapse all Bootstrap accordions with a single click of a button

Is there a simple way to toggle the collapse/expand functionality of all accordions with just one button click? I attempted to achieve this by using a basic button that would remove the 'active' class and add it back, but unfortunately, it didn&a ...

Unable to set the jQuery UI checkbox as checked or unchecked using values from an AngularJS model

Utilizing jQueryui's checkbox group feature, I have implemented three options for users to select. While I have successfully linked each checkbox to an angular model, I am facing an issue where the checkboxes do not automatically check themselves when ...

Tips for arranging records in Angularjs to give priority to display alphabetically

Hey everyone! I'm currently working on AngularJS to create a table displaying a list of records. My main challenge lies in arranging the table in ascending order, specifically ensuring that the alphabet record (X) appears as the first entry in the tab ...

The mobile menu dropdown link in jQuery is not functioning as expected

I am having an issue with my drop down menu links - they are not clickable. Every time I try to click on them, the menu just closes back to its original position and nothing happens. If you want to see the issue, you can check out my fiddle here. EDIT: T ...