如何将curl命令转换为Javascript中的$ .ajax()调用
问题描述:
我正在尝试使用jquery ajax进行Zomato API调用,但它们提供了一个curl命令。
curl -X GET --header "Accept: application/json" --header "user-key: key" "https://developers.zomato.com/api/v2.1/cities"
如何将其转换为$ .ajax()调用?
答
$.ajax({
dataType: 'json',
url: 'https://developers.zomato.com/api/v2.1/cities',
headers: {
'user-key': 'put your key in here'
}
success: function(response, status, xhr) {
// Handle the response here.
}
});
有关更多信息,请参阅JQuery API docs。