如何不用类库实现原生JavaScript AJAX请求?
- 内容介绍
- 文章标签
- 相关推荐
本文共计156个文字,预计阅读时间需要1分钟。
javascript/** * 获取ajax对象 */function getAjaxHttp() { var xmlHttp; try { // Chrome, Firefox, Opera, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject(Msxml2.XMLHTTP); } catch (e) { // IE5, IE6 } }}
/** * 得到ajax对象 */ function getajaxHttp() { var xmlHttp; try { //chrome, Firefox, Opera 8.0+, Safari xmlHttp = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { //IE5,6 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { //IE7以上 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("您的浏览器不支持AJAX!"); return false; } } } return xmlHttp; } /** * 发送ajax请求 * url--url * methodtype(post/get) * con (true(异步)|false(同步)) * parameter(参数) * functionName(回调方法名,不需要引号,这里只有成功的时候才调用) * (注意:这方法有二个参数,一个就是xmlwww.baidu.com","post",true,createxml(),c,document);
本文共计156个文字,预计阅读时间需要1分钟。
javascript/** * 获取ajax对象 */function getAjaxHttp() { var xmlHttp; try { // Chrome, Firefox, Opera, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject(Msxml2.XMLHTTP); } catch (e) { // IE5, IE6 } }}
/** * 得到ajax对象 */ function getajaxHttp() { var xmlHttp; try { //chrome, Firefox, Opera 8.0+, Safari xmlHttp = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { //IE5,6 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { //IE7以上 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("您的浏览器不支持AJAX!"); return false; } } } return xmlHttp; } /** * 发送ajax请求 * url--url * methodtype(post/get) * con (true(异步)|false(同步)) * parameter(参数) * functionName(回调方法名,不需要引号,这里只有成功的时候才调用) * (注意:这方法有二个参数,一个就是xmlwww.baidu.com","post",true,createxml(),c,document);

