onclick="sendNews()"
버튼이 있고 데이터베이스 작업을 수행하는 PHP 스크립트가 있습니다. sendNews
이 실행될 때 $_POST
배열이 비어있는 것이 문제입니다.POST 메서드에서 ajax가 작동하지 않는 이유는 무엇입니까?
자바 스크립트 :
function sendNews()
{
var title=document.getElementById("title").innerHTML;
var body=document.getElementById("boddy").innerHTML;
var params="title="+title+"&body="+body;
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");
}
//Send the proper header information along with the request
xmlhttp.open("POST","sendnews.php",true);
xmlhttp.send(params);
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("newsAddResult").innerHTML=xmlhttp.responseText;
}
}
}
PHP :
<?php
include("../inc/functions.php");
if(!loginCheck())
header('Location: index.php');
[email protected]$_POST['title'];
[email protected]$_POST['body'];
var_dump($_POST);
$q=sprintf("insert into `news`(`id`,`title`,`body`,`time`) values(NULL,'%s','%s','%s')",$title,$body,jgmdate('l jS F Y h:i:s A'));
mysql_query($q) or die("خطا".mysql_error());
echo "با موفقیت ارسال شد";
?>
문제입니까?
코드가 눈에 띄게 보이므로 보이지 않는 것에 대해 더 궁금한 점이 있습니까? 'params'의 내용은 무엇입니까? 어떤 종류의 요소가'# title'과'# boddy'입니까? 폼 요소라면'innerHTML' 대신에'value'를 원할 것입니다. –
'sendnews.php'를 수정하여'$ _POST' 내용을 파일에 덤프하면 여전히 공백입니까? – sarnold
덧붙여 말하자면, 'boddy'라는 객체의'.innerHTML'을 요구하고 있습니다. 오타이거나 의도적입니까? – sarnold