如何使用 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 ' 只是较长网址的缩写,我不想在线发布
最佳答案
无需向数据元素添加转义...您可以发送整个对象,jQuery 会为您处理。
$.ajax({
type: 'put',
url: 'https://this.is.my/url',
dataType: 'json',
data: {
name: 'Marcus0.3',
start: 500000,
end: 1361640526000
}
});
关于javascript - REST 调用 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18067660/