SQL에서 생성 된 giftlist에 작은 문제가 있습니다. 내 목표는 각 행을 텍스트 상자와 단추가있는 양식으로 에코 한 다음 단추를 클릭하면 텍스트 상자 값과 ID 번호 (숨겨진 필드 값)를 함수에 전달하는 것입니다. 그런 다음이 함수는 값을 가져와 AJAX get 메서드를 사용하여 PHP로 전송합니다. 그러면 SQL 데이터베이스에서 제공자의 이름으로 행을 업데이트합니다. 내 코드에서 오류를 찾을 수 없으므로 이와 관련하여 저를 도와주세요.
편집 : 클릭 한 버튼을 식별하는 방법도 알아 내야합니다.
이것은 내 스크립트입니다.
<script type="text/javascript">
var aname = '';
var tid = 0;
$('.giftok').click(function()
{
if ($('.aname').val() === '')
{
alert('You have not provided your name.');
}
else
{
aname = $('.aname').val();
tid = $('.id').val();
$.ajax
({
url: "kosarba.php",
data: { ganame: aname, tid: gtid },
type: "GET",
context: document.body
}).done(function() {
alert("OK, it works.");
});
alert('Thank you!');
}
});
</script>
내 HTML + PHP는 다음과 같습니다.
echo "<table id='giftlist' align='center' font-size='10pt'>";
while($sor=mysql_fetch_array($sordb))
{
echo "<tr>
<td width='420px'>$sor[gname]</td>
<td width='65px'>$sor[gprice] Ft</td>";
if (strlen($sor[aname]) !== 0)
{
echo "<td width='200px'>Sorry, someone already bought this one for us.</td>";
}
else
{
echo "<td width='335px'><form id='rendelget'>Your name: <input type='textbox' id='aname' name='aname' value='$aname'/><input type='hidden' class='id' name='id' value='$sor[id]'/> <button type='button' id='$sor[id]' class='giftok' value='Megveszem'>Megveszem</button></form> </td>";
}
echo "</tr>";
}
echo "</table>";
당신은
variable
이름 을 잘못tid = $('.id').val()
tid
해야gtid
나는 그것이 당신의 스크립트라고 생각합니다
$(document).ready(function(){
var aname = '';
var tid = 0;
$('.giftok').click(function()
{
if($(this).closest('form').attr('name') == 'myId'){ //or id
if ($('.aname').val() === '')
{
alert('You have not provided your name.');
}
else
{
aname = $('.aname').val();
gtid = $('.id').val();
$.ajax
({
url: "kosarba.php",
data: { ganame: aname, tid: gtid },
type: "GET",
context: document.body
})
.error(function(){
alert('Ajax worked but error form server.');
})
.done(function() {
alert("OK, it works.");
});
alert('Thank you!');
}
}
});
})
// 업데이트 : 버튼을 들고있는 양식을 식별하면 양식에 이름 또는 ID를 입력합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다