Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
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 answers
Answer question

0

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

about 4 years ago · Santiago Trujillo Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!