[英]Ajax, JavaScript, PhP get value from a td and save it in an SQL database
How can I get the value of a td, when I click on that spepcific td and save the value in an sql database. 当我单击那个特定的td并将值保存在sql数据库中时,如何获取td的值。 The table is build in this way: 该表以这种方式构建:
$calendar.= '<td class="calendar-day" value="'.$current_day.'">';
$calendar.= '<p>Nurse: '.$nurse_number.' </p><p>Senior: '.$senior_number.' </p>';
$calendar.= '</td>';
Thank you very much! 非常感谢你!
You have to use ajax. 您必须使用ajax。 here is a sample code: 这是一个示例代码:
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
or if you use jquery this is the syntax: 或者,如果您使用jquery,则语法如下:
$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
Try This : 尝试这个 :
$('td').click(function(){
$.ajax({
type: "POST",
url: "some.php",
data: { value:$(this).attr('value') }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
});
Get value on some.php and save it to database. 在some.php上获取价值并将其保存到数据库。
M. M.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.