Files
SOP/sop-admin/sop-admin-front/assets/lib/easyopen/index.html
tanghc d1f33d4e19 admin
2019-03-14 12:51:23 +08:00

136 lines
3.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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)
}
});
/* ****************上传文件**************** */
&lt;form id=&quot;frm&quot;&gt;
上传文件1&lt;input type=&quot;file&quot; name=&quot;headImg&quot;/&gt;
上传文件2&lt;input type=&quot;file&quot; name=&quot;idcardImg&quot;/&gt;
&lt;/form&gt;
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>