|
|
@@ -0,0 +1,87 @@
|
|
|
+<include file="Common/header" />
|
|
|
+<style type="text/css">
|
|
|
+ input{
|
|
|
+ width: 100%;
|
|
|
+ }
|
|
|
+</style>
|
|
|
+<div id="layout" style="width: 70%;margin: auto;">
|
|
|
+ <form class="form-horizontal">
|
|
|
+ <h2 style="text-align: center;">GET和POST测试</h2>
|
|
|
+ <div class="control-group">
|
|
|
+ <div class="controls">
|
|
|
+ <label >接口地址(如:http://www.abc.com/api/login)</label>
|
|
|
+ <select style="width: 100px;" id="method" >
|
|
|
+ <option value="post">POST</option>
|
|
|
+ <option value="get">GET</option>
|
|
|
+ </select>
|
|
|
+ <input type="text" id="url" placeholder="接口地址" value="http://wx.91anbu.com/ecmobile/controller/user/signin.php">
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="control-group">
|
|
|
+ <div class="controls">
|
|
|
+ <label >参数(如:user_id=121&age=22&date=2016-06-02)</label>
|
|
|
+ <input type="text" id="params" placeholder="参数" value="name=13152126786&password=123456&type=1">
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="control-group">
|
|
|
+ <div class="controls">
|
|
|
+ <button type="button" class="btn btn-primary" id="http-submit">提交</button>
|
|
|
+ <button type="reset" class="btn btn-link" >清除</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="control-group">
|
|
|
+ <div class="controls">
|
|
|
+ <label >返回结果</label>
|
|
|
+ <textarea style="width: 100%;height: 300px;" id="http-response"></textarea>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </form>
|
|
|
+</div>
|
|
|
+<include file="Common/footer" />
|
|
|
+<script type="text/javascript">
|
|
|
+ $(function () {
|
|
|
+ //格式化json数据
|
|
|
+ function dump(arr,level) {
|
|
|
+ var dumped_text = "";
|
|
|
+ if(!level) level = 0;
|
|
|
+
|
|
|
+ //The padding given at the beginning of the line.
|
|
|
+ var level_padding = "";
|
|
|
+ for(var j=0;j<level+1;j++) level_padding += " ";
|
|
|
+ if(typeof(arr) == 'object') { //Array/Hashes/Objects
|
|
|
+ var i=0;
|
|
|
+ for(var item in arr) {
|
|
|
+ var value = arr[item];
|
|
|
+ if(typeof(value) == 'object') { //If it is an array,
|
|
|
+ dumped_text += level_padding + "\"" + item + "\" : \{ \n";
|
|
|
+ dumped_text += dump(value,level+1);
|
|
|
+ dumped_text +=level_padding +"\}";
|
|
|
+ } else {
|
|
|
+ dumped_text += level_padding + "\"" + item + "\" : \"" + value + "\"";
|
|
|
+ }
|
|
|
+ if(i<Object.getOwnPropertyNames(arr).length-1){
|
|
|
+ dumped_text+=", \n";
|
|
|
+ }else{
|
|
|
+ dumped_text+=" \n";
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ } else { //Stings/Chars/Numbers etc.
|
|
|
+ dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
|
|
|
+ }
|
|
|
+ return dumped_text;
|
|
|
+ }
|
|
|
+ $("#http-submit").on('click',function () {
|
|
|
+ $.post("?s=home/page/ajaxHttpApi",{
|
|
|
+ url:$("#url").val(),
|
|
|
+ method:$("#method").val(),
|
|
|
+ params:$("#params").val()
|
|
|
+ },function (data) {
|
|
|
+
|
|
|
+ console.log(JSON.parse(data));
|
|
|
+ var text="\{ \n"+dump(JSON.parse(data))+" \}";//整体加个大括号
|
|
|
+ $("#http-response").val(text);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+</script>
|