2

Javascript (または ajax または jquery) を使用して REST Api を呼び出すにはどうすればよいですか?

curl -v -X PUT -H "Content-Type: application/json" -H "Accept: application/json" -X PUT --user user:password http://url -d "{\"name\": \"Marcus0.2\",\"start\": 1361381326000,\"end\": 1361640526000}"

これを使用可能な ajax 呼び出しに変換する助けが必要です。ありがとう

$.ajax({
    type: 'put',
    url: 'https://this.is.my/url',
    dataType: 'json',
    data: { \"name\": \"Marcus0.3\" , \"start\": 500000 , \"end\": 1361640526000 }
    });

このコードは機能しません [理由は不明]。また、「https://this.is.my/url」は、オンラインで投稿したくない長い URL の略です。

4

1 に答える 1

2

データ要素にエスケープを追加する必要はありません...オブジェクト全体を送信でき、jQuery が処理します。

$.ajax({
  type: 'put',
  url: 'https://this.is.my/url',
  dataType: 'json',
  data: {
    name: 'Marcus0.3', 
    start: 500000,
    end: 1361640526000 
  }
});
于 2013-08-05T21:12:05.027 に答える