function jsAjax() { var Con; var XmlRequset; var AjaxContent; //返回内容 if (window.XMLHttpRequest) { //判断浏览器是否支持XMLHttpRequest类 ie6以上支持 XmlRequset = new XMLHttpRequest(); } else { //不支持调用 使用 ActiveXObject类 ie6和ie5 XmlRequset = new ActiveXObject("Microseft.XMLHTTP"); } XmlRequset.open("POST", "index.aspx/GetAjax", false); //调取方法 XmlRequset.onreadystatechange = function () { if (XmlRequset.readyState == 4 && XmlRequset.status == 200) { //readystate 返回 0: 请求未初始化 1: 服务器连接已建立 2: 请求已接收 3: 请求处理中 4: 请求已完成,且响应已就绪 //status 返回 200: "OK" 404: 未找到页面 Con=XmlRequset.responseText; AjaxContent = XmlRequset.responseText; //读取返回值 document.getElementById(‘test‘).innerHTML = AjaxContent; } } XmlRequset.setRequestHeader(‘Content-Type‘, ‘application/json; charset=utf-8‘); XmlRequset.setRequestHeader(‘SOAPAction‘, "GetAjax"); XmlRequset.send(); return Con; } function jsAjax() { var Con = ""; $.ajax({ type: "post", contentType: "application/json", url: "index.aspx/GetAjax", data: "", dataType:"json", async: false, success: function (resfe) { Con = resfe.d; } }) return Con; }
时间: 2024-10-10 06:31:11