我使用AJAX接收表单数据并使用POST方法将其发送到Web服务。我尝试使用Occurs check: cannot construct the infinite type: a ~ [a]
Expected type: [a] -> [a] -> [a]
Actual type: a -> [a] -> [a]
Relevant bindings include it :: [a] (bound at :253:1)
In the first argument of ‘foldl’, namely ‘(:)’
In the expression: foldl (:) [] [1 .. 5]检索信息,因为它将更改数据库中的数据。当ajax方法设置为$a = $_POST["accommodation"]或POST且Web服务正在使用时,它可以正常工作
GET但不是$a = $_GET["accommodation"]。
JS:
$a = $_POST["accommodation"]
PHP
function ajaxrequest()
{
var xhr2 = new XMLHttpRequest();
xhr2.addEventListener ("load", (e) =>
{
var output = ""; // initialise output to blank text
var data = JSON.parse(e.target.responseText);
output = data;
if(e.target.status==201)
{
document.getElementById('response').innerHTML = "Successfuly booked!"
}
else if(e.target.status=404)
{
document.getElementById('response').innerHTML = "Sorry fully booked for this date!"
}
});
var a = document.getElementById("accommodation").value;
var b = document.getElementById("username").value;
var c = document.getElementById("accid").value;
var d = document.getElementById("npeople").value;
var e = document.getElementById("date").value;
xhr2.open("POST" , "task2.php?accommodation=" + a + "&username=" + b + "&accid=" + c + "&npeople=" + d + "&date=" + e);
xhr2.send();
}
我尝试过以下操作,但仍然无法正常工作?
header("Content-type: application/json");
$a = $_POST["accommodation"];
$b = $_POST["npeople"];
$c = $_POST["date"];
$d = $_POST["username"];
$e = $_POST["accid"];
$conn = new PDO ("mysql:host=localhost;dbname=***;", "***", "***");
$result = $conn->query("select * from acc_dates where accid=$e and thedate=$c");
$row = $result->fetch();
if($row["availability"] >= $b)
{
echo json_encode(header("HTTP/1.1 201 Created"));
$result = $conn->query("insert into acc_bookings (accID, thedate, username, npeople) values ($e, $c, '$d', $b)");
$result = $conn->query("update acc_dates set availability = availability + -$b where accid=$e and thedate=$c");
}
else
{
echo json_encode(header("HTTP/1.1 404 Not Found"));
}
我也不能使用jquery。