【问题标题】:GraphQL POST queryGraphQL POST 查询
【发布时间】:2018-02-10 15:21:52
【问题描述】:

我有一个 POST 请求要发送到我的 GraphQL 服务器。我已成功使用 Postman 并设法发送和接收响应。这是我发送到服务器的正文。

{
    article(text:"Bangkok is in Thailand"){
        id
        info
    }
}

如何将其转换为 jQuery 中的 POST 请求,以便我的 GraphQL 服务器接受它?要点击的网址是“http://localhost:8080/query

非常感谢任何帮助。谢谢。

【问题讨论】:

    标签: jquery postman graphql


    【解决方案1】:

    您可以为此使用 jQuery.post() 方法,您可以通过设置 jQuery.post() 函数的 data 参数来发送实际的 GraphQL 查询作为请求的主体。在代码中,如下所示

    $.post({
      url: 'http://localhost:8080/query',
      data: JSON.stringify({ "query": "  article(text:"Bangkok is in Thailand"){ id info}" }),
    
      contentType: 'application/json'
    
    }).done(function(response) {
      console.log('');
    });
    

    【讨论】:

      猜你喜欢
      • 2021-01-23
      • 2021-01-16
      • 2020-11-16
      • 2019-06-27
      • 2019-04-06
      • 2018-03-14
      • 2018-10-19
      • 2020-03-05
      • 2016-05-06
      相关资源
      最近更新 更多