ajax post请求get,AJAX POST请求就像GET一样?

我使用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。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值