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 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据