-1

I am trying to use trueMd.in api. But i am unable to get the response. The url is correct as i am getting response by just pasting the url in the browser. But the code is not working Kindly help.

<!DOCTYPE html>
<html>
    <head>

<div id="id01"></div>

<script>
var xmlhttp = new XMLHttpRequest();
var url = "http://www.truemd.in/api/medicine_suggestions/?id=Benadryl&key=ApiKey";

xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        var myArr = JSON.parse(xmlhttp.responseText);
        myFunction(myArr);
    }
    alert(xmlhttp.readyState);
}
xmlhttp.open("GET", url,true);
xmlhttp.send();

function myFunction(arr) {
    var out = "";
    out=arr;
    document.getElementById("id01").innerHTML = out;
}
</script>

</head>
</html>
LJ2015
  • 1

2 Answers2

0

try

function myFunction(arr) {
    var out = "";
    for(var i=0; i<arr.length; i++){
     out+=arr[i];
    }
    document.getElementById("id01").innerHTML = out;
}
ozil
  • 6,930
  • 9
  • 33
  • 56
  • Getting Error No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access'. – LJ2015 Apr 17 '15 at 19:15
0

TrueMD apis are now deprecated. Visit HealthOS for the updated APIs.

Daniel Huang
  • 6,238
  • 34
  • 33