<?php
include('db_connect.php');
include('order_functions.php');
$email = $_SESSION['username'];
$cartId = getcartid($mysqli, $email);
$notes = $_POST['notes'];
$itemID = $_POST['itemId'];
$query = "UPDATE `rel` SET `notes` = '$notes' WHERE `cart_id` = '$cartId' && `id_item` = '$itemID'";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
if(result) {
return "Notes Updated";
} 당신은 당신의 PHP 코드에서 마지막 경우 문에서 $를 잊어 버렸습니다 "return"대신 "echo"(또는 비슷하게)를 사용해야합니다.
<?php
include('db_connect.php');
include('order_functions.php');
$email = $_SESSION['username'];
$cartId = getcartid($mysqli, $email);
$notes = $_POST['notes'];
$itemID = $_POST['itemId'];
$query = "UPDATE `rel` SET `notes` = '$notes' WHERE `cart_id` = '$cartId' && `id_item` = '$itemID'";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
if($result) {
echo "Notes Updated";
}
?>
HTML/자바 스크립트 코드가 약간 잘못되었습니다. `)
<div id="<?php echo $item_id; ?>_div">
<textarea id="<?php echo $item_id; ?>_textarea" data-id="<?php echo $item_id; ?>"><?php echo htmlentities($notes); ?></textarea>
</div>
$('#<?php echo $item_id; ?>_textarea').on('blur', function() { // don't forget # to select by id
var id = $(this).data('id'); // Get the id-data-attribute
var val = $(this).val();
$.ajax({
type: "POST",
url: "updateNotes.php",
data: {
notes: val, // value of the textarea we are hooking the blur-event to
itemId: id // Id of the item stored on the data-id
},
success: function (msg) {
$('#' + id + '_div').html(msg); //Changes the textarea to the text sent by the server
}
});
});
행운
왜 당신이 사용하는'데이터 (이 내가 당신이 일을하고 싶었 추측 어떻게? 요소에'data- *'속성이 없습니다. – undefined
... 대신 무엇을 사용할 수 있습니까? 귀하의 답변은 제가 잘못하고있는 것을 이해하는 데 도움이되지 않습니다. –