首页 > 解决方案 > 数组中每个项目的 jQuery API 调用(插入查询)

问题描述

这是我第一次使用 API,我在本地机器上创建了一个非常简单的 REST API,并带有一个非常简单的 jquery 前端。我试图找出使用我的 ajax post 调用我的 API 在我的数据库中创建一个新项目的最佳方式。

// sample code:
$.ajax({
  url: "http://localhost/first_attempt/api/product/create.php",
  type: "POST",
  contentType: 'application/json',
  data: {
    "client_name": "foo",
    "date": "2020-01-01",
    "value": "2",
    "item": "report_viewer"
  },
  success: function(result) {
    bootbox.alert("Value has been added successfully.", showValues());
  },
  error: function(xhr, resp, text) {
    console.log(xhr, resp, text);
  }
});

我希望能够在for循环中使用它,但我不确定如何在每次调用从 API 获取响应时如何做到这一点,并且不使用请求重载 API,然后它不会完成。

您可以分享的任何建议将不胜感激。

标签: jqueryhtmljsonapi

解决方案


推荐阅读