php ajax 500错误,php ajax post 500 (Internal Server Error) 問題

php + jquery + mysql 表單資料無法寫入資料庫

放上服務器submit後 出現

POST https://test.online/001.php 500 (Internal Server Error)

XHR finished loading: POST "https://chienweiluo.online/001.php".

在本地端調適(127.0.0.1) 是

POST http://127.0.0.1:63943/001.php 404 (Not Found)

我網上查都是說路徑的問題, 可我已經把路徑弄妥了, 直接與./index.html 在同一層, 還是報錯各位大神幫看看吧

001.php

$data = $_POST;

$dbhost = 'chienweiluo.online';

$dbuser = 'chienlxd_wei';

$dbname = 'chienlxd_reply';

$dbpasswd = 'chienwei0526';

$dsn = "mysql:host=".$dbhost.";dbname=".$dbname;

try

{

$conn = new PDO($dsn,$dbuser,$dbpasswd);

$conn->exec("SET CHARACTER SET utf8");

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

}

catch(PDOException $e)

{

echo "Connection failed: ".$e->getMessage();

}

$sql = "INSERT INTO `users`(name, email, content,time) VALUES(:name, :email, :content,:time)";

$dataArr = array(

':name' => $data['name'],

':email' => $data['email'],

':content' => $data['content'],

':time' => $data['time']);

try

{

$sth = $conn->prepare($sql);

if($sth)

{

$result = $sth->execute($dataArr);

if($result)//true or false

{

$result = 'success';

echo json_encode($result);

return;

}

else

{

$result = 'failed';

echo json_encode($result);

return;

}

}

}

catch(PDOException $e)

{

echo "執行預存程序失敗. ".$e->getMessage();

}

?>

ajax& form

$(document).ready(function(){

$("input[type='submit']").on('click', function(){

$.ajax({

url: './001.php',

method : "POST",

dataType : 'json',

data : $("#form").serialize(),

complete : function(result) {

console.log("coplete"+result);

},

error: function(result) {

console.log("erroe"+result);

}

})

});

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值