dpr81047 2012-10-18 18:02
浏览 35

从JQuery UI获取数据可拖动并存储在数据库中

This is what I want to do:

I want to take the data associated with my draggable divs when they are dropped onto my droppable div and then store the data in a MySQL database, using PHP.

Please note that there will be multiple draggable divs that will be dropped on a single droppable div.

Also, the data will NOT be stored immediately; they will be stored at the click of a button when all the divs have been dragged.

How can this be achieved?

  • 写回答

1条回答 默认 最新

  • doujindou4356 2012-10-18 18:48
    关注

    You should use jQuery or another JS Tool / Framework to fire an AJAX request to your application. Build an interface which takes data e.g. the divId and the userId as well as the positionId. Note that you have to check the session by using the userId because the application security is affected if you allow this for each user. You should return JSON (json_encode FTW!) to communicate with your javascript script.

    Database:

    id, userId, divId, positionId
    1, 1, 1, 2
    1, 1, 2, 1
    

    PHP:

    <?php
    $positionId = $_GET['positionId'];
    $divId      = $_GET['divId'];
    $userId     = $_GET['userId']; // make sure that this userId is equal to your session
    
    // init db
    // check for existing entity (e.g. the div already exist for this user)
    $db->query("INSERT INTO position SET userId = :userId, divId = :divId, positionId = :positionId");
    // execute
    json_encode(array('success' => true));
    

    JS:

    $.ajax({
        url: '/your_script.php',
        params: {
            userId: 1,
            positionId: 1,
            divId: 1
        },
        dataType: 'json',
        success: function(response) {
            if (response.success) {
                // display feedback
            }
        }
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号