Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
I am trying to display a paragraph of text in HTML but I need to create it as a JSON object and read it with AJAX to do so. My code is not working

I have tried to iterate through the JSON object but it is not working. Is there a more efficient way to even structure the object? Also, I am not sure that the AJAX request is being made because I keep seeing an error message which is "There was a problem: 0".

This is my JS file:

$(document).ready(function() {
    $.ajax({
        type: "GET",
        url: "lab4.json",
        dataType: "json",
        success: function(response){

            var message = "";
            
            $.each(responseData.text, function(i, item) {
                $.each(item.tutoring-text, function(x, s) {
                    message += s;  
                });     
            });  
            $("#tutoring-text").html(message);
        }, 
        error: function(msg) {
              // there was a problem
              alert("There was a problem: " + msg.status + " " + msg.statusText);
        }
      });
    
  });

This is my JSON file:

{
    "text":{
        
        "tutoring-text": [
        
            "Gamma Nu Eta holds weekly tutoring sessions every Wednesday.",
            "At these tutoring sessions, GNH can help you with any course in your ITWS degree program.",
            "This includes ITWS core classes, such as Intro to ITWS and Web Systems, or classes outside of ITWS, such as Computer Science 1 and Data Structures.",
            "We can also help with any questions that you might have about career development, resumes, as well as just general questions about RPI."      
        ]  
        
    } 
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You're trying to iterate when your JSON structure is reasonably flat.

All you really need is

$("#tutoring-text").html(response.text["tutoring-text"].join(""))
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda