duanbi9202 2012-08-23 10:00
浏览 77

使用angularjs将记录插入mysql数据库

i wish to insert a record in mysql table using angularjs. Table: Product product_id, name, description.

i wish to have two text fields and a save button and on the click of save button record should be inserted in mysql table. i referred to the following link :

but all in vain...

index.html

    <html ng-app>
    <head>
        <script src="../angular-1.0.1.min.js"></script>
        <script src="js/controllers.js"></script>
    </head>
    <body>
    <ul ng:controller="ProductListCtrl">
        <li ng:repeat="product in products">
            {{product.name}}
        </li>
    </ul>
    <form method = 'post'>
        Name : <input type = 'text' name = 'txtName'/>
        Description : <input type = 'text' name = 'txtDescription'/>
        <button ng:click="saveProduct()">New Product</button>
        <div id="content">
            <ng:view></ng:view>
        </div>
    </form>
    </body>
</html>

where do i write saveProduct() method and what should i write in it?

what should i do to add a record in mysql from angularjs?

  • 写回答

3条回答 默认 最新

  • duanboxue3422 2012-08-23 10:20
    关注

    AngularJS is a client side MV* framework. Most Client side frameworks expect that the decision with regard to the DOM manipulation be left to them and they be just fed the data from the server side.

    This data will ofcourse in your case be stored in MySQL which you will have to retrieve through PHP and write a simple RESTful interface to your DB. In your angular code, say your PHP restful endpoint would be something like

    http://mywebsite.com/api/product

    If you do a simple POST call through ng-resource it is equivalent to making a save on your DB. For details on how to set this up, you could have a look at some of the ng-resource examples floating around.

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名