I have been wondering how my website can obtain remote JSON data and parse it.
Google has a lot on the internet, how to obtain remote data through AJAX, and finally found a sentence in w3cschool.
The first key:
With AJAX, your JavaScript can communicate directly with the server, using the JavaScriptXMLHttpRequestObject. With this object, your JavaScript can trade data with a web server, without reloading the page.
It turns out that XMLHttpRequest is used to send a request.
The second sentence is critical:
The XMLHttpRequest object is supported in Internet Explorer 5.0 +, Safari 1.2, Mozilla 1.0/Firefox, Opera 8 +, and Netscape 7.
This request supports most browsers.
The third key is how to create this Request:
<Script type = "text/javascript">
Function ajaxFunction ()
{
Var xmlHttp;
Try
{
// Firefox, Opera 8.0 +, Safari
XmlHttp = new XMLHttpRequest ();
}
Catch (e)
{
// Internet Explorer
Try
{
XmlHttp = new ActiveXObject ("Msxml2.XMLHTTP ");
}
Catch (e)
{
Try
{
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Catch (e)
{
Alert ("Your browser does not support AJAX! ");
Return false;
}
}
}
}
</Script>
Well. With the above basic knowledge, you will know how to play with AJAX. You will know how to obtain JSON.
Reference:
Http://www.w3schools.com/Ajax/default.asp