The issue arises when trying to apply CSS and minified JavaScript after adding new data in jQuery Mobile

I am having an issue with adding data and displaying it on a list. The problem arises when I add data through AJAX. In the success function, after showing the alert "successfully added", I used location.reload(), which takes me to the homepage (div tag data-role="page") instead of staying on the current page. When I replace the reload function with window.location.hash='#id_of_myDiv_page', the data displays correctly but the CSS and CDN minified JavaScript are not working, causing the list tags to appear very large. This is a major problem for me.

Here's my code:

 $("#b4").click(function (){         
       $.ajax({
         type:"POST",
         url:"http://manoj/adddoc.php",
         data: $("#frm1").serialize(),
         success:function(response)
         {                       
            if(response == 1)
            {    
               alert("Record Added Successfully");
               managedoctor(); // calling function
               window.location.hash = '#managedoctor'; 
            }                          
            else
            {
               alert("Error while adding the data");                      
            }
        }
    });  
});   

function managedoctor()
{
    $.ajax({
        async: true,
        type: "GET",
        url: "http://manoj/doctor_details.php",
        dataType: 'JSON',
        success:function(response)
        {
            var list = "";
            if(response.length != 0)
            { 
                for (var i = 0; i < response.length; i++) 
                { 
                    list += '<li doc_id="' + response[i].id + '"><img src="doctor.png"/><p><h3><a href="#adddoc" data-rel="dialog" data-transition="flip" id="' + response[i].id + '">' + response[i].docname + '</a></h3></p></li>';
                }    
            }
            if(list != "")
            {
                $("#myListView").html(list);   
            } 
        }
    });    
}

**HTML Page:**

<div data-role="page" id="managedoctor" data-theme="b" data-add-back-btn="true">
    <div data-role="header" data-position="fixed">
        <a id="refreshdoctor" href="#adddoc" data-rel="dialog" data-transition="flip">Add Doctor</a>
    </div>
    <div id="doctorlist">
        <ul id="myListView" data-inset="true" data-role="listview" data-theme="c" data-filter="true" data-filter-placeholder="Search doctors..." style="margin-top:30px!important;"></ul>
    </div>       
</div>

Answer №1

Give this a shot:

Refresh the ListView by using the following code: $("#myListView").listview( "refresh" );

For more information, check out:

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 an image using AJAX and Flask

I have a situation in HTML where I need to constantly update an image file with the latest images that come in. Below is the Flask code snippet: @app.route('/uploads/update_file', methods=['GET', 'POST']) def update_file(): ...

Overlaying Divs and UI Blocking

I am currently working on an ASP.net project where I have a web page that contains both design time controls and run time generated controls. The dynamically generated content, such as a table, is appended to a div on the page known as a container div, wit ...

Can Google Charts columns be customized with different colors?

Is it possible to modify the colors of both columns in Google's material column chart? Here is the code I am using for options: var options = { chart: { title: 'Event Posting', subtitle: 'Kairos event p ...

Transferring a data variable from JavaScript through $_POST method

In an attempt to transfer a variable from a JavaScript function to my PHP file, I have extracted the user_name from a cookie using JavaScript and then used AJAX to $_POST the variable to my PHP file for further processing. Instead of submitting the POST va ...

What is causing an increase in height for an inline-block element when using overflow: hidden?

When exploring this specific example, the mysteries of CSS and HTML unfold... HTML Structure <body> <div> <div>foo bar</div> </div> </body> CSS Style Rules body, html, div { height: 100%; margin: 0; } di ...

What causes the inconsistency in CSS Hover behavior?

Looking to devise a button in css and html that reveals another button below it by rotating on its lowermost axis when hovered over. Progress has been made here: http://codepen.io/machinarius/pen/BdtCb However, there seems to be an issue with the hover b ...

Creating personalized headers for ajax requests in combination with php

Can anyone help me troubleshoot an issue I'm having with retrieving custom headers from an ajax call? Here is the ajax call in question: $.ajax({ url: 'api.php', type: 'get', processData: false, beforeSend: functi ...

Optimizing images for various screen sizes with responsive design

As I delve into using responsive images, a question has arisen. On my website, there is an icon that comes in two sizes: a small version measuring 74 pixels wide and a larger version at 94 pixels wide. <img alt="Section Gino" style="background-color: ...

Issue with checkbox alignment in Twitter Bootstrap v3.x

Greetings fellow siblings. I am facing an issue with Twitter Bootstrap checkboxes, particularly when viewed in Opera, Chrome, and IE. Here is the problem: I have come across this snippet of code <div class="form-group"> ...

What steps can be taken to strip HTML tags from an RSS feed using a shell script and then export the cleaned data as a

My issue lies in parsing an XML feed and extracting two fields (title and link), which is functioning correctly. I am now seeking a way to strip away all HTML tags and store the result in a CSV format, as shown below: title,link title,link title,link ...

Is there a way for me to have a table automatically scrolled to a specific column upon loading the HTML page?

My table contains a dynamic number of columns based on the months inputted from the database starting from a start_date and ending at an end_date. I have the current_date stored as a variable and want the table to load with the x-scrollbar positioned right ...

Attempting to implement a feature that will enable a blank row at the end of an input table with the help of

I'm currently working on a form that allows users to click a button to add a blank row to the bottom of a table. The issue I'm facing is that when I click the button, it redirects back to my index.php page instead of simply adding the row to the ...

Issue with jQuery AJAX Event Handling

I'm currently struggling to solve a bug in an existing ASP.NET MVC website. One of the views includes a set of text boxes where users input data. Each text box triggers some JavaScript on the blur event to send changes back to the server. Specificall ...

Creating Horizontal Repeating Cards in Three Columns with Bootstrap 4: Cards

I want to create a layout like the one shown below: card1 card2 card3 card4 card5 card6 card7 card8 card9 card10 card11 card12 card13 card14 card15 etc....(using asp.net repeater control) INSTRUCTION: I need the cards to be displayed horizontally in thre ...

Steps for placing a menu link at the far right edge of the menu

I'm looking to customize my NAVBAR by adding a Donate Link Menu on the right side, next to the search icon. Can anyone help with this simple task? Thank you in advance! Here is the link to the website: www.clihelp.org Below is the menu code for my N ...

Optimizing HTML and Script loading sequences for efficient execution

I have a query regarding the loading order of scripts in web browsers. I am interested in knowing the most efficient way to redirect users to a mobile website on the client side. For example, if I place a mobile detection script within the <head> se ...

Create a simulated API in Angular by utilizing JasonPlaceholder to retrieve information upon clicking a button

I am currently developing a dummy API using jsonplaceholder. I have managed to retrieve all posts after clicking a button, but now I want to display the user ID and title by default on page load. Additionally, when clicking on a post's title, I would ...

How to transform the bootstrap 4 hamburger icon into a three dots menu icon using css only

The standard bootstrap 4 navigation bar button showcases a classic hamburger icon. <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample03" aria-controls="navbarsExample03" aria-expanded="false" aria-label="T ...

Transform SVG with a Click

Can someone assist me with rotating the pink area on click and moving it to a new angle from its current position? I am looking for a way to save the current position of the pink area and then, when clicked, move it smoothly to a new position. Your help ...

Is 'not set' in Google Analytics indicating the browser version?

I came across a similar question on Stack Overflow, but my situation is unique. After adding the Google Analytics script to my project (Angular4), I noticed that I am receiving all information except for browser information. Some browsers are showing &apo ...