"Utilizing AJAX with JSON in PHP, the callback function is integrated with

Recently, I encountered an issue while developing a web app using Jquery Mobile. I had to make an Ajax/Json request to a PHP file in order to retrieve data from MySQL database. However, when I received the JSON callback and tried to create a "list" from the array, the path of the jQuery Mobile CSS file seemed to be lost and my HTML structure was not well formed.

$.ajax({
    url: "busca_reservas.php",
    data: "fecha=" + fecha + "",
    dataType: 'json',   
    type: "POST",
    cache: false,
    success: function(data){
        var output = '<ul data-role="listview" data-inset="true" id="reservas" class="listareservas">';

        var logsData = data;
        for (var i in logsData.logs){
            regis  = logsData.logs[i].recid;
            nombre  = logsData.logs[i].nombre;
            ape     = logsData.logs[i].apellido;
            output+= '<li><a href="#">' + regis + "  " + nombre + " " + ape + '</a></li>';

        }
        output+='</ul>';

        $('.listareservas').listview('refresh');
        $("#result").append(output).fadeIn(500);

        console.log(output)
    }
});

Instead of seeing the content as a visually appealing Jquery Mobile "List View", it appeared as plain text in my browser. If anyone has any suggestions on how to resolve this issue, your help would be greatly appreciated.

Thank you in advance!

Answer №1

To enhance the functionality, consider placing the refresh method following the append:

    $("#result").append(output).fadeIn(500);
    $('.listareservas').listview('refresh');

Answer №2

Recalling a similar issue from my experience working on a previous project using jquery mobile, I was able to find a solution that worked:

function updateLayout() {
    $("div[data-role=page]").page("destroy").page();
}

I made sure to call this function after every successful ajax request. Depending on your project's requirements, you may need to adjust the data-role attribute to suit what needs to be updated. Hopefully, this information proves helpful!

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 best way to implement object-oriented programming to have an asynchronous AJAX request return a value upon completion?

I need assistance with the code snippet provided below. My goal is for the 'airported' object to generate a list of airports. However, I am struggling to retrieve the data once the each loop has completed its iteration in finding 'li's ...

Modify the name of the tag while preserving all of the attributes

What I currently have looks like this: <span id="anId" someOtherAttributes....>test</span> and my desired outcome is: <a id="anId" theSameOtherAttributes...>test</a> I am faced with two main questions : How ca ...

Searching by object id from the front-end: A step-by-step guide

Within my collection of meals, there is a specific document I am working with: # Meals collection { name: "burger", tag: ObjectId(63d6bb22972f5f2fa97f1506), } Now, as I navigate through my React application, I find myself needing to send a ...

What could be causing the image not to load in this code with the img tag?

import React from 'react'; import styled from 'styled-components'; function Navbar() { return ( <Container> <img src='./appleWhite.png' /> </Container> ) } export defau ...

Determine the point spread using Jquery

Trying to figure out the point spread and determine the winner of a game based on the entered scores. I've created a function to calculate the total number of points and another function to calculate the point spread and assign a winner label. However ...

"Failure to update variables within the catch block of the .map() function leads to inconsistencies

Greetings Sorcerers, I have been utilizing .map() to loop through an array of Objects. Following some data manipulations and assigning values to specific variables, I am inserting them into a postgres database. const insertIntoDB = (jsonObj) => { le ...

Having trouble deleting the value and deselecting the checkbox item?

Feeling a bit confused about a coding issue I'm facing. The problem lies in the categories listed in my database, which I fetched and used to create a post. Now, I'm attempting to edit that post. The categories are in checkbox format, where check ...

Having trouble with Jquery autocomplete feature not functioning properly. Struggling to assign a value to the data response using jQuery.map()

Currently in the process of learning jQuery within MVC. Everything appears to be working smoothly except for the autocomplete feature, which is not functioning as expected. After debugging, it seems that the success method may be the issue. Any assistance ...

What is the importance of typescript requiring the use of generics?

const typeFunction = <T>(a:string, {c,d} = {c: T[], D:T} = {})=>{} In what way does TypeScript enforce the usage of generics? I am looking to create a function that requires a specific type (T) to be passed in when it is used. typeFunction<st ...

Utilizing dropzone.js for file uploads triggered by clicking with ASP.NET Service

Hello everyone and thank you in advance for your help. I am trying to implement a Dropzone.js Upload box on my webpage where users can drag and drop files into the box and then click a button to upload them to a folder using a backend API. However, I am fa ...

The customization of a class within an array loop is not functioning properly

I'm facing an issue where I've added a class (question) to each element in an array, and the loop is running smoothly. However, I'm having trouble getting jQuery to recognize the class - it's almost as if it doesn't exist... I sus ...

Tips for sending information to a child component from a parent in Vue.js

Is there a way to pass the image url to this vue component? I am moving the code to a separate php file that will contain the <script> tag used by Vue, but it seems like it won't recognize the passed data from a parent component. Vue.component( ...

Using jquery to target and manipulate elements with the div selector

I need assistance with adding a selector on my webpage where users can choose one option and retrieve the id of the selected part. This id will then be used in a link. I am new to using jQuery, so I am having trouble implementing this feature. Below is an ...

Error message in ASP.Net MVC when using JQuery: Receiving an undefined return

How can I modify my .Net MVC controller to successfully return a value using an SQL query that involves an Email field? Currently, the email is being read by the query but the resulting value is not being transferred over to the View with Json. Here is th ...

CSS class malfunction - various classes with identical functions

I'm new to the world of web development and design, embarking on a journey to learn all I can in these fields. Recently, I attempted to create unique hover styles for each menu button within my CSS classes-based menu list. However, I encountered an i ...

What is the process for sending a GET request to fetch the most recent document from an index in the Elasticsearch cluster?

I've been working on a node.js application to fetch the most up-to-date index value from an elastic cluster. The data is streamed from my logstash server into elasticsearch every second, resulting in the index being updated with a new document added e ...

Updating the search list in md-autocomplete based on the input from another md-autocomplete in AngularJS

I am in need of assistance with updating the search list of my second <md-autocomplete> drop-down based on the selection made in the first drop-down. You can take a look at an example plunker which is not currently functioning properly: http://p ...

JavaScript lacks support for linear transformation and matrix multiplication functions, causing them to be

Currently, I am delving into the complexities of linear algebra and experimenting with crafting a simple program that incorporates fundamental linear transformations (rotating, scaling, translating). Behold, here is a fully functional example: https://cod ...

Utilizing an HTML time picker for scheduling specific time intervals

Is it possible to use an HTML time picker with a specific interval? https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time According to the link, the step attribute is supported, but I have tested it on the latest versions of Chrome, Edge, ...

How can a function work with an array of subarrays of objects without altering the original array?

Within a small coding project I recently completed, I handled an array consisting of 3 subarrays, with each subarray containing 4 objects. I passed this array through a function that gradually removes values from each subarray until only 1 object remains i ...