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

158
Visualizações
I can't seem to generate content for dynamic content load

I am using wordpress and php along with ajax to create a random loading of customer reviews on our main page

function loadContent() {
  $.ajax({
    type: "GET",
    url: 'http://skillsetsonline.ssosv.com/contentLoader.php',
    data: {
      company: 1
    },
    success: function(data) {
      alert(data);
      var currReview = document.getElementById('reviewRand');
      currReview.innerHTML = data;
    }
  });
}
setTimeout(loadContent, 10000); // milliseconds, so 10 seconds = 10000ms
<div id="reviewRand" class="elementToFadeInAndOut" style="font-color:#FFF;">Hi how are you</div>

I pasted the ajax command in from a stackoverflow posting that was an accepted answer but may not have it exactly right this does not include the fading CSS code I use but that is working I just need to change the content. Currently "Hi how are you" fades in every 10 seconds. One thing I have not learned about yet with this ajax command is the

data:{company:1}

I know it simply passes &company=1 to the GET URL but in my case I do not need to send anything and since it should not break anything if it is sent I left it alone not sure if

data:{}

would work and be cleaner I have verified that the url used does get a random review formatted like this

I love this program.blah blah.<br>
A USER<br>
A location<br>
June 2016<br>

Each line is formatted in CSS via a class tag

Any ideas would be greatly appreciated

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Since the domain you're making the AJAX request to is on a different domain/origin, what you're running in to is a CORS issue. By default, the client will not allow you to update the page with data from an AJAX request that is served on a different origin than the site where the request originated. You can read about making CORS changes here https://enable-cors.org/

A common way around this is to serve the response via JSONP. You can do this in your script at http://skillsetsonline.ssosv.com/contentLoader.php if you have access to change that file. There are also third-party sites that will request that URL for you and create a proxy that serves the response via JSONP, then you can use it on your website.

Here's an example utilizing a JSONP proxy on https://crossorigin.me

function loadContent() {
  $.ajax({
    type: "GET",
    url: 'https://crossorigin.me/http://skillsetsonline.ssosv.com/contentLoader.php',
    success: function(data) {
      var currReview = document.getElementById('reviewRand');
      currReview.classList.add('ready');
      currReview.innerHTML = data;
    }
  });
}

setTimeout(loadContent, 0); /* changed this for the demo */
#reviewRand:not(.ready) {
    text-align: center;
}   
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="reviewRand"><img src="http://thinkfuture.com/wp-content/uploads/2013/10/loading_spinner.gif"></div>

about 4 years ago · Santiago Trujillo 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