You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							136 lines
						
					
					
						
							3.3 KiB
						
					
					
				
			
		
		
	
	
							136 lines
						
					
					
						
							3.3 KiB
						
					
					
				<!DOCTYPE html>
 | 
						|
<html>
 | 
						|
<head>
 | 
						|
<meta charset="UTF-8">
 | 
						|
<title>sdk</title>
 | 
						|
<script type="text/javascript" src="sdk.js"></script>
 | 
						|
<script type="text/javascript">
 | 
						|
//需要发布到服务器上运行,并且server端需要处理跨域
 | 
						|
//在IndexController.java上加@CrossOrigin(origins={"*"})
 | 
						|
 | 
						|
// 初始化配置,执行一次即可
 | 
						|
sdk.config({
 | 
						|
    url : 'http://localhost:8080/api'
 | 
						|
    ,app_key : 'test'
 | 
						|
    ,secret : '123456'
 | 
						|
});
 | 
						|
 | 
						|
sdk.get({
 | 
						|
	name   : 'goods.get' // 接口名
 | 
						|
// 	,version:'1.0'
 | 
						|
// 	,access_token:''
 | 
						|
	,data  : {'goods_name':'iphone'} // 请求参数
 | 
						|
	,callback:function(resp) { // 成功回调
 | 
						|
		console.log(resp)
 | 
						|
	}
 | 
						|
});
 | 
						|
</script>
 | 
						|
</head>
 | 
						|
<body>
 | 
						|
 | 
						|
<h1>打开F12查看效果</h1>
 | 
						|
 | 
						|
<fieldset>
 | 
						|
    <legend>GET/POST</legend>
 | 
						|
    <button onclick="getTest()">GET</button>
 | 
						|
    <button onclick="postTest()">POST</button>
 | 
						|
</fieldset>
 | 
						|
<hr>
 | 
						|
<fieldset>
 | 
						|
    <legend>上传文件demo</legend>
 | 
						|
    <form id="frm">
 | 
						|
	    头像图片:<input type="file" name="headImg"/> <br><br>
 | 
						|
	    身份证图片:<input type="file" name="idcardImg"/>
 | 
						|
	</form>
 | 
						|
    <br>
 | 
						|
    <button onclick="uploadTest()">上传文件请求</button>
 | 
						|
</fieldset>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<pre>
 | 
						|
//需要发布到服务器上运行,并且server端需要处理跨域
 | 
						|
//在IndexController.java上加@CrossOrigin(origins={"*"})
 | 
						|
 | 
						|
sdk.config({
 | 
						|
    url : 'http://localhost:8080/api'
 | 
						|
    ,app_key : 'test'
 | 
						|
    ,secret : '123456'
 | 
						|
});
 | 
						|
 | 
						|
sdk.get({
 | 
						|
    name   : 'goods.get' // 接口名
 | 
						|
    ,data  : {'goods_name':'iphone'} // 请求参数
 | 
						|
    ,callback:function(resp) { // 成功回调
 | 
						|
        console.log(resp)
 | 
						|
    }
 | 
						|
}); // get方式不支持上传
 | 
						|
 | 
						|
sdk.post({
 | 
						|
    name   : 'goods.get' // 接口名
 | 
						|
    ,data  : {'goods_name':'iphone'} // 请求参数
 | 
						|
    ,callback:function(resp) { // 成功回调
 | 
						|
        console.log(resp)
 | 
						|
    }
 | 
						|
});
 | 
						|
 | 
						|
 | 
						|
/* ****************上传文件**************** */
 | 
						|
<form id="frm">
 | 
						|
    上传文件1:<input type="file" name="headImg"/>
 | 
						|
    上传文件2:<input type="file" name="idcardImg"/>
 | 
						|
</form>
 | 
						|
 | 
						|
function uploadTest() {
 | 
						|
    sdk.get({
 | 
						|
        name   : 'file.upload' // 接口名
 | 
						|
        ,data  : {'goods_name':'iphone'} // 请求参数
 | 
						|
        ,form  : document.getElementById('frm')
 | 
						|
        ,callback:function(resp) { // 成功回调
 | 
						|
            if(resp.code == '0') {
 | 
						|
                alert('上传成功,' + resp.msg);
 | 
						|
            } else {
 | 
						|
                alert('上传失败,' + resp.msg)
 | 
						|
            }
 | 
						|
        }
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
</pre>
 | 
						|
 | 
						|
<script type="text/javascript">
 | 
						|
function uploadTest() {
 | 
						|
	sdk.post({
 | 
						|
	    name   : 'file.upload' // 接口名
 | 
						|
	    ,data  : {'goods_name':'iphone'} // 请求参数
 | 
						|
	    ,form  : document.getElementById('frm')
 | 
						|
	    ,callback:function(resp) { // 成功回调
 | 
						|
	        if(resp.code == '0') {
 | 
						|
	        	alert('上传成功,' + resp.data);
 | 
						|
	        } else {
 | 
						|
	        	alert('上传失败,' + resp.msg)
 | 
						|
	        }
 | 
						|
	    }
 | 
						|
	});
 | 
						|
}
 | 
						|
function getTest() {
 | 
						|
	sdk.get({
 | 
						|
        name   : 'goods.get' // 接口名
 | 
						|
        ,data  : {'goods_name':'iphone'} // 请求参数
 | 
						|
        ,callback:function(resp) { // 成功回调
 | 
						|
            console.log(resp);
 | 
						|
        }
 | 
						|
    });
 | 
						|
}
 | 
						|
function postTest() {
 | 
						|
	sdk.post({
 | 
						|
	    name   : 'goods.get' // 接口名
 | 
						|
	    ,data  : {'goods_name':'iphone'} // 请求参数
 | 
						|
	    ,callback:function(resp) { // 成功回调
 | 
						|
	        console.log(resp);
 | 
						|
	    }
 | 
						|
	});
 | 
						|
}
 | 
						|
</script>
 | 
						|
</body>
 | 
						|
</html> |