javascript - php做app介面的問題

來源:互聯網
上載者:User
關鍵字 php javascript html
這是用戶端的代碼:

        $(document).ready(function(){            $("button").click(function(){                $.ajax({                    url: 'server.php',                    type: 'POST',                    timeout: 30000,                    error: function(){                        alert('請求出錯');                    },                    success: function(msg){                        alert(msg);                    }                });            });        });    

服務端代碼:

我只知道大概是這個原理,不知道具體怎麼做規範,求教!

回複內容:

這是用戶端的代碼:

        $(document).ready(function(){            $("button").click(function(){                $.ajax({                    url: 'server.php',                    type: 'POST',                    timeout: 30000,                    error: function(){                        alert('請求出錯');                    },                    success: function(msg){                        alert(msg);                    }                });            });        });    

服務端代碼:

我只知道大概是這個原理,不知道具體怎麼做規範,求教!

RESTful API 設計指南[阮一峰]

http://www.ruanyifeng.com/blog/2014/05/restful_api.html

現在最普遍的就是restful 當然也不一定要按照這個標準來實現,其實最簡單的可以實現功能,內部定好介面的格式就可以了

如果在實際開發中
1.響應類response.class,其中包含不同請求方式的處理,需要至少三個變數,$code狀態代碼,$message資訊提示,$data處理資料,一個傳回值json或者xml
2.單例模式資料庫類db.class封裝,資料庫的操作都放在裡面
3.需要一個app介面文檔

具體你可以參考慕課網上有一個php app介面的課程,很全面

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.