PHP(十四)ajax

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>ajax</title>
    <script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
   <p>zzzz</p> 
   <div>点击</div> 
   <form id="main"> 
       <input type="file" name="ues" id="fuj"> 
       <span></span> 
       <br/> -->
       <input type="button" onclick="sub();" value='提交'> 
    </form>
    
    <script type="text/javascript">
    	//$.post
// 		$('div').click(function()
// 			{
// 				var str = $('p').text(); 
// 				$.post('img.php',{aaa:str},function(dat){
// 					alert(dat);
// 				})
// 			}
// 		)
    
    	//$.ajax
// 		function sub()
//         {
//             var user = $('input[name=ues]').val();
//             $.ajax({
//                 type : "post",
//                 data : {aaaa:user},
//                 url    : "img.php",
//                 success : function(dat)
//                 {	
//                     $('span').html(dat);
//                     alert("提交成功");
//                     document.getElementById('main').reset();
//                 }
//             })
//         }

		//new XMLHttpRequest(); GET[]
// 		function loadXMLDoc(url,cfunc)
// 		{
// 			xmlhttp = new XMLHttpRequest();
// 			xmlhttp.onreadystatechange=cfunc;
//             xmlhttp.open("GET",url,true);
//             xmlhttp.send();
// 		}
// 		function sub()
// 		{
// 			var user = $('input[name=ues]').val();
// 			loadXMLDoc("img.php?aaa="+user,function()
// 				{
//     				if(xmlhttp.readyState==4){
//     					$('span').html(xmlhttp.responseText);
//     					alert("提交成功");
//                         document.getElementById('main').reset();
//     	            }
// 				})
// 		}
		//new XMLHttpRequest(); POST[]
// 		function sub()
// 		{
// 			var user = $('input[name=ues]').val();
// 			var xmlhttp = new XMLHttpRequest();
// 			xmlhttp.onreadystatechange=function()
// 			{
// 				if (xmlhttp.readyState==4 && xmlhttp.status==200)
// 				{
// 					$('span').html(xmlhttp.responseText);
// 					alert("提交成功");
//                  document.getElementById('main').reset();
// 				}
// 			}
// 			xmlhttp.open("POST","img.php",true);
// 			//表单方式提交添加
// 			xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
// 			xmlhttp.send('aaa='+user);
// 		}
    </script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_38904347/article/details/83961284