logo
down
shadow

Load multiple json files and display it to the html using ajax and jquery


Load multiple json files and display it to the html using ajax and jquery

By : Emilien Garreau
Date : October 18 2020, 01:08 AM
hope this fix your issue I am trying to grab three different json files that contain objects and load them into a single page using the jquery get method. I need to grab the objects and display all three to the page using jquery. I am having trouble loading and displaying all three... any help is appreciated. ! , Instead of .html() method use .append() of JQuery.
code :
$(document).ready(function() {
  var url = "https://rawgit.com/typicode/json-server/master/routes.json";
  $("button").click(function() {
    $.get(url, function(data) {
      $('#mydiv').append((JSON.stringify(data)));
    });
    $.get(url, function(data) {
      $('#mydiv').append((JSON.stringify(data)));
    });
    $.get(url, function(data) {
      $('#mydiv').append((JSON.stringify(data)));
    });
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" name="button">Click Me</button>

<div id="mydiv">

</div>


Share : facebook icon twitter icon
jQuery load multiple html files in one element

jQuery load multiple html files in one element


By : Bill K
Date : March 29 2020, 07:55 AM
it fixes the issue How do i load multiple html files and putting them into a specified html element? , you could get multiple items and add them to the element.
code :
jQuery.ajaxSetup({ async: false }); //if order matters
$.get("file.htm", '', function (data) { $("#result").append(data); });
$.get("pippo.htm", '', function (data) { $("#result").append(data); });
jQuery.ajaxSetup({ async: true });  //if order matters
Autorefreshing/updating table using jQuery ajax by either using json or html files

Autorefreshing/updating table using jQuery ajax by either using json or html files


By : shivani
Date : March 29 2020, 07:55 AM
Does that help using ajax is very simple,
I recommend you to use HTML datatype for this as you have a table in your container,
code :
function updateClass(url){
    $.ajax({
        url: url,
        dataType: "HTML",
        error: function(msg){
            alert(msg.statusText);
            return msg;
        },
        success: function(html){
            $("#container").html(html);
        }
    });
}
function refreshClass(){
            updateClass("http://fiddle.jshell.net/sijav/mQB5E/5/show/"); //update the class
}
var classUpdateI; //stands for our interval updating class
$(".class-selector").on("change",function(){
    if (classUpdateI!=null)clearInterval(classUpdateI); //If the selector changed clear the interval so the container won't be update on it's own
    if(this.value == "")
        return; // if the value is null don't do anything
    else if(this.value == "allclassnup"){
        refreshClass(); //if the value is allclassnup which is stands for All Non-Updating just refresh the whole class 
    }
    else if(this.value == "allclassup"){
        refreshClass(); //if the value is allclassup which is stands for All Updating refresh the whole class and set an interval for thirty second (look for 30*1000)
        classUpdateI = setInterval(refreshClass,30*1000);
    }
    else //else then it's a simple class value, just simply update the current class
        updateClass(this.value);
})
if(readCookie("CurrentClass")) //if we can read coockie
    $(".class-selector").val(readCookie("CurrentClass")).change(); //change it's value to current cookie and trigger the change function
else{ // else
    selectSelectedClass(); //select those which was highlighted before
    trClick(); //make things clickable
    FirstTimeInit = false; //and turn of the first time init
}
        success: function(html){
            $("#container").html(html + '<a id="KEY"></a>'); //the html container changer with adding extra id , I'll explain it later it's for your second question
            if(FirstTimeInit){ //if it is First Time then
                selectSelectedClass(); //highlight which was highlighted after put the correct html
                FirstTimeInit = false; // turn of the first time init
            }
            else //else
                for (var i=0;i<($("table").children().length);i++){
                    if(readCookie(i))
                        eraseCookie(i); //erase every cookie that has been before because the table is now changed and we're going on another table so old cookie won't matter
                }
            trClick(); //make things selectable!
        }
function refreshClass(){
    if(readCookie("CurrentClass")=="allclassnup"||readCookie("CurrentClass")=="allclassup"||readCookie("CurrentClass")==null)
        FirstTimeInit = true;
    updateClass("http://fiddle.jshell.net/sijav/mQB5E/5/show/");
}
$("#PreviousClass").click(function(){//on prev click
    $(".class-selector").val($(".class-selector option:selected").prev().val()).change() //change the value to the prev on and trigger the change
});

$("#NextClass").click(function () {//on next click
    $(".class-selector").val($(".class-selector option:selected").next().val()).change() //change the value to the prev on and trigger the change
});
currentClass=0;
$("a.TOPJS").click(function () {
    if(currentClass>0){
        currentClass--
        scrollToAnchor('CLASS'+currentClass);
    }
});

$("a.KEYJS").click(function () {
    if($("a[id='CLASS" + currentClass + "']")[0]!=undefined){
        currentClass++
        scrollToAnchor('CLASS'+currentClass);
    }
    else
        scrollToAnchor('CLASSMAX');
});
classUpdateI = setInterval(function(){updateClass(this.value,parseInt(a.charAt(a.length-1),10));},30*1000);
function trClick(tIndex){ //tIndex would be classnumber from now on
    if (tIndex == -1){ //if it is all updating or all non updating
        $("tr").click(function(){ //do the previous do
            $(this).toggleClass('selected').siblings().removeClass('selected');
            if(readCookie($(this).parent().index("tbody"))){
                if(readCookie($(this).parent().index("tbody"))==$(this).index())
                    eraseCookie($(this).parent().index("tbody"));
                else{
                    eraseCookie($(this).parent().index("tbody"));
                    createCookie($(this).parent().index("tbody"),$(this).index(),1);
                }
            }
            else
                createCookie($(this).parent().index("tbody"),$(this).index(),1);
        });
    }
    else{ //else
        $("tr").click(function(){ //on click
            $(this).toggleClass('selected').siblings().removeClass('selected');//do the toggle like before
            if(readCookie(tIndex)){ //if you can read the CLASS cookie, not the current index of table because our table has only one row
                if(readCookie(tIndex)==$(this).index()) //as before if we selecting it again
                    eraseCookie(tIndex); //just erase the cookie
                else{ //else
                    eraseCookie(tIndex); //select the new one
                    createCookie(tIndex,$(this).index(),1);
                }
            }
            else
                createCookie(tIndex,$(this).index(),1); //else if we can't read it, just make it!
        });
    }
}
Display rows from database in html table using jQuery, Ajax, json

Display rows from database in html table using jQuery, Ajax, json


By : user2371930
Date : March 29 2020, 07:55 AM
I hope this helps . I think this maybe your problem, you are returning an array from get_classes($Opportunity_Id) but you have not captured that array when you call it :-
code :
function get_classes() {
    $Opportunity_Id = $this->input->post('Opportunity_Id');
    $classes = $this->ion_auth_model->get_classes($Opportunity_Id);   <--- changed here

    foreach ($classes as $class):
        $results[] = array(
                        "Class_Number" => $class->Class_Number,
                        "Class_Date" => $class->Class_Date,
                        "Start_Time" => $class->Start_Time,
                        "End_Time" => $class->End_Time
                    );
    endforeach;

    echo json_encode($results);
}
Display json data from jQuery.ajax in HTML using loop

Display json data from jQuery.ajax in HTML using loop


By : Adam
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You can loop through your data.results within your "success function", like this:
code :
jQuery.ajax({
    type: "GET",
    url: "https://myurl.com",
    success: function(data)
    {
        console.log(data);

        jQuery.each(data.results, function(i, val) {
            // here you can do your magic
            $("#yourdivid").append(document.createTextNode(val.term));
            $("#yourdivid").append(document.createTextNode(val.count));
        });
    }
});
Cant display json data into html using Jquery Ajax post method

Cant display json data into html using Jquery Ajax post method


By : user2792934
Date : March 29 2020, 07:55 AM
wish of those help There is more than one issue with your code, so I will explain why to you in detail.
If you are sending trough POST, send the data.
code :
        $.ajax({
            type: "POST",
            url: '/cart',
            data: $(this).serialize(), // Call the form values as a string
            success: function(data) {
                console.log(data);
                $("#cart-template").html(data)
            }
        })
$("#purchaseform").submit(function(event){
   ...
})
$("#purchaseform").submit(function(event){
        event.preventDefault()
        $.ajax({
            type: "POST",
            url: '/cart',
            data: $(this).serialize(),
            success: function(data) {
                console.log(data);
                $("#cart-template").html(data)
            }
        })
})
Related Posts Related Posts :
  • How to change dynamic data-src for lazy images?
  • how to apply a filter for an attribute?
  • Redirect in JavaScript without losing the form post data
  • Uglify weird characters spaces
  • Ember not detecting all attributes from server response
  • convert axisX date to text in Html5 5 line chart
  • React. setState does not update state of subcomponents
  • Replace expression between two punctuation letters in javascript
  • FabricJS circle to show radius
  • How to delete the rows corresponding to the selected `yes` input?
  • Delete image on clicking "X" mark on right top of image
  • ternary operator does not change backgroundColor
  • How I can hide the root element in a dendogram d3
  • How to pass variables to a method inside a fuction JavaScript
  • $window.location.href (angular.js:12520 TypeError: Cannot set property 'href' of undefined)
  • How to use dynamic CSS
  • How do I return the static data?
  • How can i set a label text by a javascript function without knowing the label ID in javascript
  • Chrome extension form input text is blank on submit
  • Get specific key value in a string
  • Set CSS property with js click event handler
  • How to collect all array unique values from array of objects using underscore?
  • Polyfill to list the HTTP headers of a Header's instance
  • Checking if the input fields are filled in properly (pure javascript)
  • Replace an expression in string using javascript
  • Iterating for loop for set number of iterations each time it is called until the end of an array
  • How to use JQuery on a WordPress Page/Post
  • Angular Error: Unknown provider: dataserviceProvider
  • jQuery - Why it replaces the value twice?
  • Hide all countries list in a select dropdown and show only Belgium/BE using jquery
  • Skip jQuery validation when div element is hidden
  • Display time calculation in full format
  • How to rotate in 3D many rect in SVG with a different angle of rotation?
  • Datatables not working when loading specific page though id
  • ReactJS: How to rerender component after fetching data
  • In Mapbox how can you toggle layers from a style on iOS?
  • Could installing Dreamweaver affect how your browser runs scripts?
  • Detect virtual keyboard on screen and landscape orientation in javascript
  • JSON: Uncaught SyntaxError: missing ) after argument list
  • Trigger classList for * in JavaScript
  • jQuery function - set String parameter
  • Using associative arrays in javascript
  • Simple bar chart d3
  • How to get private variables from prototyped methods in Javascript
  • How do I route a string to a function based on a regex match?
  • Is it okay to add/remove classes in stateless react component
  • Jquery array loop
  • Toggle disabled attribute of paper-button
  • Ask user permission to expire the session
  • handle dojo EdgeToEdgeStoreList event
  • How to edit File in perfoce with node js?
  • What is the DOM event when slider button stops moving
  • Param as router - ExpressJS
  • How can I make my popup appear smoothly after 5 seconds?
  • Change type of paper-input programmatically
  • How to access results of a promise at a later part of a chain
  • Remove click function, but keep hover intact
  • What is it called when I can select a HTML element in JS using it's ID?
  • Deploy folder in CWD using Shipit JS
  • React: show object as working JS format?
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com