简体   繁体   English

我想发布json数据并获取响应数据

[英]i want to post the json data and get the response data

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  </head>
  <body>


<script>
var SendInfo= { SendInfo: [{"dataKey":"1013"}]};

        $.ajax({
            type: 'post',
            url: '/getData',
            data: JSON.stringify(SendInfo),
            contentType: "application/json",
            traditional: true,
            success: function (data) {
                console.log(data);
            }
        });
</script>

</body>
</html>

i am parsing the json data but i am getting the 500 server error but everything seems to work fine in postman plese suggest any changes 我正在解析json数据,但出现500服务器错误,但在邮差中一切正常,建议进行任何更改 在此处输入图片说明

Have you checked the request you are sending and compared the ajax request to the postman request on the server side? 您是否检查了要发送的请求并将ajax请求与服务器端的邮递员请求进行了比较?

You seem to be sending two different JSONs, in your ajax code you have { SendInfo: [{"dataKey":"1013"}]} and in your postman request you have just {"dataKey":"1013"} . 您似乎正在发送两种不同的JSON,在ajax代码中,您有{ SendInfo: [{"dataKey":"1013"}]}而在邮递员请求中,您只有{"dataKey":"1013"} These are different objects and your back end might not understand them both. 这些是不同的对象,您的后端可能无法同时理解它们。

只有您需要在发帖请求中发送此信息。

var SendInfo= {"dataKey":"1013"};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想将JSON数据传递给与Web视图相关的javascript函数。 但是我无法从Javascript函数中获取响应数据 - I want to pass JSON data to javascript function related to web view. But I am unable to get the response data from the Javascript function 获取json数据响应? - Get json data response? 我有一个API,我想从api响应中获取数据 - I have an API, I want to get the data from api response 如何以带有JSON正文的POST形式发送数据,并导航至响应? - How can I send data as a POST with a JSON body, and navigate to the response? 发布后如何获取响应数据? - How do I can get response data after I post it? 我想将“KEY”和“textValue”的数据存储为 json 并将其作为 node.js 中的响应发送给 app.get("/api", (req, res) - I want to store the data of "KEY" & "textValue" as a json and send it as response in node.js for app.get("/api", (req, res) 当我想从 Json 数据或 API 与 axios.get 获取或获取某些特定字段时,response.data.key 返回未定义 - response.data.key return undefined when i want to grab or get some specific fields from Json data or API with axios.get 我想通过ajax调用从地图获取json数据 - i want to get json data from map through ajax call 我想从 json 对象的数组中获取数据的总和 - I want to get the sum of data from array of the json object 我想从json数据中获取我的价值 - I want to get my value from json data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM