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

229
Visualizações
ajax get json from web API but return error

I use ajax to get json from a web API as following.

The browser log shows that json result is extracted, but the page returned the error function: alert("Please try later"). browser log image Is there anything wrong?

Thanks!

$.ajax({  
   url :"http://dgidb.genome.wustl.edu/api/v1/interactions.json", 
   type:"get",  
   async:false,  
   data: {genes: genes, interaction_sources: interaction_sources},
   dataType:"jsonp",
   jsonp:"callback",
   jsonpCallback:"message",
   success: function(data){  
      alert(data);
   },
   error: function(){  
      alert("Please try later");
   } 
}); 
about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Remove dataType:"jsonp" or use dataType:"json"

about 4 years ago · Santiago Trujillo Relatório

0

Using your code I could not get it to work unless I added quotes around the "genes" and "interaction_sources".

If I access the url: http://dgidb.genome.wustl.edu/api/v1/interactions.json directly it says: {"error":"You must enter at least one gene name to search!"}

Perhaps instead of the "genes" and "interaction_sources" you should be using search parameters?

EDIT: if you could provide the API for the json you are trying to access we might be able to debug it?

$("#runme").on("click", function() {
  RunMe();
});

function RunMe() {
  $.ajax({
    url: "http://dgidb.genome.wustl.edu/api/v1/interactions.json",
    type: "get",
    async: false,
    data: {
      genes: "genes",
      interaction_sources: "interaction_sources"
    },
    dataType: "jsonp",
    jsonp: "callback",
    jsonpCallback: "message",
    success: function(data) {
      alert(data);
    },
    error: function() {
      alert("Please try later");
    }
  });

};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>

<button id="runme">RUN ME!!!</button>

about 4 years ago · Santiago Trujillo Relatório

0

Ensure API response date with application/json header

{
  "matchedTerms": [],
  "unmatchedTerms": [
    {
      "searchTerm": "GENES",
      "suggestions": []
    }
  ]
}

This response's Content-Type would be application/json. I tried this is on POSTMAP manually and it worked. Just fixed the Content-Type header value.

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