MySQL-How do I use jquery, Ajax, PHP to implement such a no-refresh editing function?

Source: Internet
Author: User

Let me do the work first. If 1 is the pre-editing effect, figure 2 is the effect of clicking on "Modify Inventory". HTML and CSS have been made, but JavaScript is not understood. Modified data directly through the background PHP modified to MySQL, if successful, return the data directly to the inventory TD cell.

Then there is my HTML code.

        3308    3.97 M³    2950.00 元    2013-05-21 14:36:20        保存修改

Ask the brothers to give a detailed answer, really do not understand JavaScript ah, the entire page is poor this one function realized. In addition, such a table has a long column, I can use the PHP loop to generate Dynamic HTML tag ID.

Thanks Thank you!

Reply content:

Let me do the work first. If 1 is the pre-editing effect, figure 2 is the effect of clicking on "Modify Inventory". HTML and CSS have been made, but JavaScript is not understood. Modified data directly through the background PHP modified to MySQL, if successful, return the data directly to the inventory TD cell.

Then there is my HTML code.

        3308    3.97 M³    2950.00 元    2013-05-21 14:36:20        保存修改

Ask the brothers to give a detailed answer, really do not understand JavaScript ah, the entire page is poor this one function realized. In addition, such a table has a long column, I can use the PHP loop to generate Dynamic HTML tag ID.

Thanks Thank you!

The above answer, I did not adopt the answer, it is my level is limited, not modified. The problem was also raised in Php100, which was soon resolved. The following php100 the answer, and attach links to facilitate others.


  
   
  <title>Untitled Document</title>
  
  
3308 3.97 M3 2950.00 Yuan 2013-05-21 14:36:20 0 units in Stock Modify Inventory
3308 3.97 M3 2950.00 Yuan 2013-05-21 14:36:20 0 units in Stock Modify Inventory

Above is the HTML page, below is the PHP


  
    '错误!',    'status' => FALSE,    'num' => 0);if(isset($_POST['id']) && isset($_POST['num'])){    if(is_numeric($_POST['id']) && is_numeric($_POST['num'])){        $id = (int)$_POST['id'];        $num = (int)$_POST['num'];        $r['msg'] = '修改成功!';        $r['num'] = $num;        $r['status'] = TRUE;    }else{        $r['msg'] = '错误![2]';    }}else{    $r['msg'] = '错误![1]';}echo json_encode($r);?>

$(document).ready(function() {//为每一个具有相同id=cartUpdate 的 添加click事件$("#cartUpdate").live("click",function(){    var text=$(this).text();    if(text=="修改数量"){        var count = $(this).parent().prev().text();        $(this).parent().prev().html("");        $(this).text("确定");    }else if(text=="确定"){        var count2 = $(this).parent().prev().children().val();        var id = $(this).parent().prev().prev().prev().prev().text();        $.post("/cart/update", {            "productId" : id,"count":count2        }, function(data) {            if(data=="ok"){                $("#p" + id).next().next().next().text(count2);                $("#p" + id).nextAll().find("button").text("修改数量");            }else{                alert("修改失败");            }        });    }});
  • 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.