Sunday 30 April 2017

jquery - unable to get the results from the yahoo finance api for my site due cross domain funcationality





if (window.XMLHttpRequest)
{

xmlhttp=new XMLHttpRequest();

}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","http://finance.yahoo.com/d/quote.csve=.csv&s=^BSESN&f=nl1c2vgh&random=10",true);

xmlhttp.send(null);

xmlhttp.onreadystatechange=function()

{

if (xmlhttp.readyState==4)
{
window.alert(xmlhttp.status);
}
}


The above code showing status 200 in IE But in Firefox and Chrome got the status 0 due cross domain functionality.

Can any one help to how to overcome this cross domain functionality using java script.


Answer



Direct call to other domain is not possible from JavaScript ajax due to cross domain issue best way to do this type of call is call your own webpage using Ajax and from your server side script call these apis and get answer and return to your ajax call.



if you are using php you can use cURL OR file_get_contents to fetch content from url


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...