javascript-php do the App interface problem

Source: Internet
Author: User
Keywords Php javascript html
Here is the code for the client:

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

Service-Side code:


  
   

我只知道大概是这个原理,不知道具体怎么做规范,求教!

Reply content:

Here is the code for the client:

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

Service-Side code:


  
    

我只知道大概是这个原理,不知道具体怎么做规范,求教!

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接口的课程,很全面

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.