아약스를 사용하여 차단 된 IP 주소로 데이터베이스를 업데이트 할 수 있도록 스크립트를 작성하려고합니다. 따라서 페이지를 벗어날 필요가 없습니다. 순간에 나는 블록 버튼을 누르면 성공 메시지를 제공하지만, 데이터베이스를 보면 날짜가 업데이트되어 현재 사용 중이므로 실제로 변수를 얻지 못합니다. 그러나 다른 두 필드는 비어 있지만 문제가 어디 있는지 찾을 수 없습니다, 나는 새로운 아약스 및 그래서 모든 포인터 감사 할 것입니다, 감사합니다.AJAX 인서트가 여러 항목을 만들지 만 데이터가 없음
양식
<div id="insert_response"></div>
<!-- Form: the action="javascript:insert()"calls the javascript function "insert" into ajax_framework.js -->
<form action="javascript:insert()" method="post" class="block">
<div align="center">
<input name="id" type="hidden" id="id" value="<?php echo "$id"; ?>"/>
<input name="ip" type="hidden" id="ip" value="<?php echo "$ip"; ?>"/>
<input type="submit" name="Submit" class="block" value="Block"/> </div>
</form>
아약스
$(document).ready(function(){
$('form.block').submit(function() {
var id = $(this).find('.id').attr('value');
var ip = $(this).find('.ip').attr('value');
// ...
});
$.ajax({
type: "POST",
url: "ajax.php",
data: "id="+ id +"& ip="+ ip,
success: function(){
$('form#block').hide(function() {$('div.success').fadeIn();});
}
});
return false;
});
아약스 프레임 워크
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}
var http = createObject();
var nocache = 0;
function insert() {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('insert_response').innerHTML = "Just a second..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var ip = encodeURI(document.getElementById('ip').value);
var id = encodeURI(document.getElementById('id').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'ajax.php?id='+id+'&ip='+ip+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
function insertReply() {
if(http.readyState == 4){
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('insert_response').innerHTML = 'Added:'+response;
}
}
그리고 마지막으로는 PHP
$id = htmlspecialchars(trim($_POST['id']));
$ip = htmlspecialchars(trim($_POST['ip']));
$addClient = "INSERT INTO ipdata (ip_address, ip_check_id, date_blocked) VALUES ('$ip','$id', NOW())";
mysql_query($addClient) or die(mysql_error());
감사합니다, 지금은 아무것도 보이지 않는 것 같습니다. 내가 알아 차린 것은 데이터베이스의 필수 공백 뒤에 추가 필드가 나타납니다. [object HTMLCollection] \t [obje –
] 이것들은 처음에는 거기에 없었기 때문에 지연되었을 것입니다 –