ext--Ajax

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>ajax.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <link rel="stylesheet" type="text/css" href="/web/ext/resources/css/ext-all.css" />
    <!-- GC -->
 	<!-- LIBS -->
 	<script type="text/javascript" src="/web/ext/adapter/ext/ext-base.js"></script>
 	<script type="text/javascript" src="/web/ext/adapter/ext/ext-all.js"></script>
 	<!-- ENDLIBS -->

    <script type="text/javascript" src="/web/ext/ext-all-debug.js"></script>
    <script type="text/javascript">
    	Ext.onReady(function(){
			Ext.Ajax.request({
			   url: 'time!getTime.action',
			   success: function(response, opts) {
			   	Ext.Msg.alert("success",response.responseText);
			      //var obj = Ext.decode(response.responseText);
			      //console.dir(obj);
			   },
			   failure: function(response, opts) {
			      //console.log('server-side failure with status code ' + response.status);
			      Ext.Msg.alert("failure",response.status);
			   },
			   params:{
			   	name:'test'
			   }
			});
			
			// 提交表单。
			var button = new Ext.Button(
				{
					text:"提交表单",
					renderTo:document.body,
					handler:function(){
						Ext.Ajax.request(
							{
								form:'myform',
								params:'name'
							}
						);
					}
				}
			);		
			
			Ext.get("json").on("click",function(){
				Ext.Ajax.request(
					{
					 url:"time!getJson.action",
					 success:function(response,config){
					 	var json = Ext.util.JSON.decode(response.responseText);
					 	Ext.Msg.alert("","name="+json.name+",age="+json.age);
					 },
					 failure:function(response,config){
					 	Ext.Msg.alert("","抱歉,请求失败!");
					 }
					}
				);
			});
			
			Ext.get('uploadBtn').on('click',function(){
				//var form = Ext.get('upload').dom;
				var form = document.forms[1];
				//alert(form==Ext.get('upload').dom);
				form.target = id; // 链接form与iframe
				form.method = "post"; //必须是post
				form.enctype = form.encoding = "multipart/form-data";
				var url = "time!doUpload.action"; // 表单提交地址。
				if(url) {
					form.action = url;
				}
				Ext.Ajax.request(
					{
						url:"time!doUpload.action",
						isUpload:true,
						form:"upload",
						success:function(response,cfg){
							var result = Ext.util.JSON.decode(response.responseText);
							Ext.Msg.alert("msg",result.msg);;
						},
						failure:function(response,cfg){
							var result = Ext.util.JSON.decode(response.responseText);
							Ext.Msg.alert("msg",result.msg);
						}	
					}
				);
			});
			
		
		});
	</script>
  </head>
  
  <body>
    	<form action="time!submitForm.action">
    		<input type="text" name="name" id="name">
    	</form>
    	
    	<input type="button" id="json" value="Json">
    	<div>
    		<span>Ajax文件上传</span><br>
	    	<form id="upload">
	    		<label>选择上传文件:</label>
	    		<input type="file" name="file">
	    		<br>
	    		<label>文件描述:</label>
	    		<textarea rows="4" cols="50" name="fileDesc"></textarea>
	    		<input type="button" value="上传文件" id="uploadBtn">
	    	</form>
    	</div>
  </body>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值