jquery ajax 接口请求方式写法

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name=viewport content="width=device-width,initial-scale=1,user-scalable=0">
    <meta name="description" content="">
    <title></title>
    <link href="global.css" rel="stylesheet">
    <style>

    </style>
</head>

<body>

    <script src="jquery.min.js"></script>
    <script>
        $(function() {
            var ROOT = 'http://www.baidu.com'

            var API = {
                getBanner: ROOT + '/Mobile/getBanner'
            }

            var UTILS = {
                //json 转get请求key、value形式
                json2Form: function () {
                    var str = [];
                    for (var p in json) {
                        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(json[p]));
                    }
                    return str.join("&");
                }
            }

            var AJAX = {
                getBanner: function (success,fail) {
                    $.get(API.getBanner, function(data) {
                        if(typeof success === 'function'){
                            success(data)
                        }
                    })
                }
            }


            AJAX.getBanner(function (data) {
                console.log(1111111)
                console.log(data)
                alert(JSON.stringify(data))
            })
        })
    </script>
</body>

</html>

猜你喜欢

转载自blog.csdn.net/bbsyi/article/details/81319153