如何实现ajax的getJSON请求功能?

更新于
2026-09-29 11:50:00
1阅读来源:SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计110个文字,预计阅读时间需要1分钟。

如何实现ajax的getJSON请求功能?

javascript使用ajax的getJSON进行HTTP GET请求(返回json类型):function httpGetJSON(url, callback, async) { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject(Microsoft.XMLHTTP); } xmlhttp.onreadystatechange=function() { if (this.readyState==4 && this.status==200) { callback(JSON.parse(this.responseText)); } }; xmlhttp.open(GET, url, async); xmlhttp.send();}

如何实现ajax的getJSON请求功能?

ajax getJSON请求

// http GET请求(json类型) function httpGetJSON(url, callback, async) { var xmlhttp; xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.onreadystatechange = function() { if(4 == xmlhttp.readyState && 200 == xmlhttp.status) { try { callback(JSON.parse(xmlhttp.responseText)); } catch(e) { callback(eval("(" + xmlhttp.responseText + ")")); } } }; async = false == async ? false : true; xmlhttp.open("GET", url, true); xmlhttp.send(); };

本文共计110个文字,预计阅读时间需要1分钟。

如何实现ajax的getJSON请求功能?

javascript使用ajax的getJSON进行HTTP GET请求(返回json类型):function httpGetJSON(url, callback, async) { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject(Microsoft.XMLHTTP); } xmlhttp.onreadystatechange=function() { if (this.readyState==4 && this.status==200) { callback(JSON.parse(this.responseText)); } }; xmlhttp.open(GET, url, async); xmlhttp.send();}

如何实现ajax的getJSON请求功能?

ajax getJSON请求

// http GET请求(json类型) function httpGetJSON(url, callback, async) { var xmlhttp; xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.onreadystatechange = function() { if(4 == xmlhttp.readyState && 200 == xmlhttp.status) { try { callback(JSON.parse(xmlhttp.responseText)); } catch(e) { callback(eval("(" + xmlhttp.responseText + ")")); } } }; async = false == async ? false : true; xmlhttp.open("GET", url, true); xmlhttp.send(); };