zoukankan      html  css  js  c++  java
  • js的ajax封装

    		var basePath='<%=basePath%>';
    		/*ajax请求返回值*/
    		var response='';
    		
    		/*创建一个xmlHttp对象*/
    		var xmlHttp = false;
    		if(window.XMLHttpRequest){
    			xmlHttp = new XMLHttpRequest();
    		}else if(window.ActiveXObject){
    			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    		}
    		
    		/*使用XMLHttpRequest对象的函数,这个函数获取服务器的一个文件内容并显示到网页*/
    		function getData(urlParam,elementId){
    			if(xmlHttp){
    				alert(3);
    				var obj=document.getElementById(elementId);
    				alert(4);
    				//通过GET方法请求,将请求封装在URL中
    				/*
    				xmlHttp.open("GET",urlParam);
    				xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    				*/
    				//post请求
    				xmlHttp.open("POST", urlParam);
    				xmlHttp.onreadystatechange=callBack;//设置服务器响应的处理方法
    				xmlHttp.send(null);// 发送请求
    			}				
    		}
    		
    		/*回调函数*/
    		function callBack(){
    			if(xmlHttp.readyState==4 && xmlHttp.status==200){
    				response = xmlHttp.responseText;
    			}
    		}
    		
    		/*删除*/
    		function delPersonInfo(feilds,values,infoId,za0100,rm01id,elementId){
    			delUrl = "/gwyhr/main/appoint.dd?method=updatePersonInfo&feilds="+feilds+"&values=+"values+"&infoId="+infoId+"za0100="+za0100+"rm01id="+rm01id;
      			getData(delUrl,elementId);
      			var obj = document.getElementById(elementId);
      			if(response != ''){
      				obj.style.display="none";
      			}
      			alert(response);
      			response='';
    		}
    

      

  • 相关阅读:
    WPF TextBox 一些设置技巧
    Rust 初始配置
    Framework​Element.​Find​Name 根据名字查找控件
    C# SQLite 数据库操作
    MP3 信息读取
    C# event 事件学习
    Nginx 整合 Lua 实现动态生成缩略图
    Spring Cloud 入门 之 Config 篇(六)
    Spring Cloud 入门 之 Zuul 篇(五)
    Flyway 简单入门教程
  • 原文地址:https://www.cnblogs.com/jice/p/2458872.html
Copyright © 2011-2022 走看看