如何在javascript中实现环回卷曲?

如何在javascript中实现环回卷曲?,javascript,loopback,Javascript,Loopback,我不明白如何在javascrpt中创建post方法,例如: curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{ \"name\": \"GreatNight\", \"city\": \"Tehran\" }" "http://localhost:3000/api/CoffeeShops" javascript中的代码怎么可能是这样的?使用jQu

我不明白如何在javascrpt中创建post方法,例如:

curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{
  \"name\": \"GreatNight\",
  \"city\": \"Tehran\"
}" "http://localhost:3000/api/CoffeeShops"

javascript中的代码怎么可能是这样的?

使用jQuery
ajax

$.ajax({
  type: 'POST',
  url: "http://localhost:3000/api/CoffeeShops",
  data: {
    name: "GreatNight",
    city: "Tehran"
  },
  dataType: "json",
  accepts: {
    text: "application/json"
  }
});

使用jQuery
ajax

$.ajax({
  type: 'POST',
  url: "http://localhost:3000/api/CoffeeShops",
  data: {
    name: "GreatNight",
    city: "Tehran"
  },
  dataType: "json",
  accepts: {
    text: "application/json"
  }
});
这就是解决方案:

html

<ion-content>
  <ion-list>
    <ion-item>
      <ion-label fixed> shop name </ion-label>
      <ion-input type="text"[(ngModel)]="name" > </ion-input>
    </ion-item>

    <ion-item>
      <ion-label fixed> city </ion-label>
      <ion-input type="text" [(ngModel)]="city"> </ion-input>
    </ion-item>

    <ion-item>
      <button ion-button block large (click)="post()">post  </button>
    </ion-item>

  </ion-list>

</ion-content>
这就是解决方案:

html

<ion-content>
  <ion-list>
    <ion-item>
      <ion-label fixed> shop name </ion-label>
      <ion-input type="text"[(ngModel)]="name" > </ion-input>
    </ion-item>

    <ion-item>
      <ion-label fixed> city </ion-label>
      <ion-input type="text" [(ngModel)]="city"> </ion-input>
    </ion-item>

    <ion-item>
      <button ion-button block large (click)="post()">post  </button>
    </ion-item>

  </ion-list>

</ion-content>

cURL在Javascript中不可用。如果您谈论的是客户端(浏览器)JS,那么您需要的是AJAX请求。你可以用谷歌搜索数百个例子来说明如何做到这一点。如果您正在谈论node.js,请参见此处:。顺便说一句,不确定你在这里所说的“环回”指的是什么?@adyson,谢谢。我想在移动应用程序中使用crud api,该应用程序正在实现b、ionic并使用typescript/javascript和angular。您可能需要了解更多关于node.js的信息。@Parsaria该软件包被俗称为“curl”,但它实际上没有使用或重新实现原始curl。它只是用一些速记方法将节点的“请求”包()封装起来。另外OP已经提到他们在这里没有使用node.js。那么如何实现@Reza及其代码呢?离子使用角度可能是有帮助的。cURL在Javascript中不可用。如果您谈论的是客户端(浏览器)JS,那么您需要的是AJAX请求。你可以用谷歌搜索数百个例子来说明如何做到这一点。如果您正在谈论node.js,请参见此处:。顺便说一句,不确定你在这里所说的“环回”指的是什么?@adyson,谢谢。我想在移动应用程序中使用crud api,该应用程序正在实现b、ionic并使用typescript/javascript和angular。您可能需要了解更多关于node.js的信息。@Parsaria该软件包被俗称为“curl”,但它实际上没有使用或重新实现原始curl。它只是用一些速记方法将节点的“请求”包()封装起来。另外OP已经提到他们在这里没有使用node.js。那么如何实现@Reza及其代码呢?离子使用角度可能是有帮助的。谢谢,但我不认为jquery和Ajax能解决我在Ionic应用程序中的问题。谢谢,但我不认为jquery和Ajax能解决我在Ionic应用程序中的问题。