0
這就是我想做的事:獲取從JQuery用戶界面拖動和存儲數據的數據庫
我想帶着我的可拖動的div相關的data時候都滴到我投擲的DIV,然後將數據存儲在一個MySQL數據庫,使用PHP。
請注意,將有多個可拖動的div將放在一個可放置的div上。
此外,數據不會立即存儲;當所有div被拖動時,它們將被存儲在一個按鈕上。
這是如何實現的?
這就是我想做的事:獲取從JQuery用戶界面拖動和存儲數據的數據庫
我想帶着我的可拖動的div相關的data時候都滴到我投擲的DIV,然後將數據存儲在一個MySQL數據庫,使用PHP。
請注意,將有多個可拖動的div將放在一個可放置的div上。
此外,數據不會立即存儲;當所有div被拖動時,它們將被存儲在一個按鈕上。
這是如何實現的?
您應該使用jQuery或其他JS工具/框架來嚮應用程序發出AJAX請求。構建一個接收數據的界面divId和userId以及positionId。請注意,您必須使用userId檢查會話,因爲如果您爲每個用戶允許,應用程序安全性會受到影響。 您應該返回JSON(json_encode FTW!)以與您的JavaScript腳本進行通信。
數據庫:
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
}
}
});
嗨,你好,感謝您的答覆......只是想知道如果這是第四唯一的辦法就是做到這一點,或者,有沒有其他更有效率/專業的方式來做到這一點? –