rambod17
دوشنبه 27 مرداد 1393, 04:09 صبح
با سلام
من در حال طراحی یک سایت هستم توی این سایت از ajax رای ارسال اطلاعات استفاده کردم اما هر کاری میکنم کدهام کار نمی کنه
function PostData() {
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
else {
throw new Error("Ajax is not supported by this browser");
}
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status == 200 && xhr.status < 300) {
alert( xhr.responseText);
}
}
}
var userid = document.getElementById("title1").value;
var userp =document.getElementById("date1").value;
var userp1 =document.getElementById("content1").value;
// 3. Specify your action, location and Send to the server - Start
xhr.open('POST', 'regnews.php');
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("title1=" + userid+"&date1=" +userp+"&content1=" +userp1);
}
کد php
<?php
//$Tablename="news";
$state1=10;
$head1=trim($_POST["title1"]);
$date1=trim($_POST["date1"]);
$cont1=trim($_POST["content1"]);
//$Link=mysqli_connect("localhost","root","");
//$Query="inset into $Tablename values('$_POST[title1]','$_POST[date1]','$_POST[content1]')";
$con =mysqli_connect("localhost","root","","armane-ma");
if (mysqli_connect_errno($con))
{
echo ("error connect to data base");
}
mysqli_query($con, "SET SESSION CHARACTER_SET_RESULTS =utf8");
if($head1=="" || $date1=="" || $cont1=="")
{
echo ("0");
}
else
{
$query1="INSERT INTO news (title11,date11,news11) VALUES ('$head1','$date1','$cont1')";
if (!mysqli_query($con,$query1))
{
die('Error: ' . mysqli_error($con));
}
else
{
echo "1";
}
}
mysqli_close($con);
?>
لطفا کمک کنید کجاش مشکل داره؟
من در حال طراحی یک سایت هستم توی این سایت از ajax رای ارسال اطلاعات استفاده کردم اما هر کاری میکنم کدهام کار نمی کنه
function PostData() {
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
else {
throw new Error("Ajax is not supported by this browser");
}
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status == 200 && xhr.status < 300) {
alert( xhr.responseText);
}
}
}
var userid = document.getElementById("title1").value;
var userp =document.getElementById("date1").value;
var userp1 =document.getElementById("content1").value;
// 3. Specify your action, location and Send to the server - Start
xhr.open('POST', 'regnews.php');
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("title1=" + userid+"&date1=" +userp+"&content1=" +userp1);
}
کد php
<?php
//$Tablename="news";
$state1=10;
$head1=trim($_POST["title1"]);
$date1=trim($_POST["date1"]);
$cont1=trim($_POST["content1"]);
//$Link=mysqli_connect("localhost","root","");
//$Query="inset into $Tablename values('$_POST[title1]','$_POST[date1]','$_POST[content1]')";
$con =mysqli_connect("localhost","root","","armane-ma");
if (mysqli_connect_errno($con))
{
echo ("error connect to data base");
}
mysqli_query($con, "SET SESSION CHARACTER_SET_RESULTS =utf8");
if($head1=="" || $date1=="" || $cont1=="")
{
echo ("0");
}
else
{
$query1="INSERT INTO news (title11,date11,news11) VALUES ('$head1','$date1','$cont1')";
if (!mysqli_query($con,$query1))
{
die('Error: ' . mysqli_error($con));
}
else
{
echo "1";
}
}
mysqli_close($con);
?>
لطفا کمک کنید کجاش مشکل داره؟