发送带有Ajax的帖子-错误的请求问题 [英] sending post with ajax - bad request issue
问题描述
我只是从API入手,我需要一点帮助...
Im just starting with API and I need a little bit of help...
我有此代码:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
</head>
<body>
<script type="text/javascript">
var json=`{
"Teamname": "example",
"Password": "example",
"members": [{
"name": "John",
"surname": "Doe",
},
{
"name": "Kate",
"surname": "Smith",
},
{
"name": "Brad",
"surname": "Warden",
},
{
"name": "Antony",
"surname": "McLeer",
}
]
}`;
$.ajax({
type: "POST",
url: "http://52.233.158.172/change/api/en/account/register",
data: "json",
contetType: "application/json"
});
console.log(json);
</script>
</body>
</html>
我在控制台中收到返回错误的请求,我经过几次代码,一切都应该正常工作,但是显然缺少某些东西
and I get for return bad request in console, I go through code several times and everything should just work fine but obviously something is missing
如果我和邮递员一起去,我会得到200 OK的答复...有人可以帮助我我想念的是什么吗?
Also if i go with postman I get 200 OK response...can anybody help me what Am I missing?
推荐答案
当您需要发送变量json时,您似乎在帖子数据中发送了字符串"json".
It looks like you are sending a string "json" in your post data when you need to send the variable json instead.
如果将ajax请求更新为:
If you update your ajax request to:
$.ajax({
method: "POST",
url: "http://52.233.158.172/change/api/en/account/register",
data: json,
contentType: "application/json"
});
请注意删除第4行中json周围的引号.
Note the removal of the quotes around json on line 4.
希望这会有所帮助.
这篇关于发送带有Ajax的帖子-错误的请求问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!