如何使用 Meteor 从 API 导入 http 请求(JSON 格式)
How to import a http request (JSON format) from an API with Meteor
我被困在Meteor上,我目前正在寻求从带有http请求的API导入数据。我通过 ajax 请求找到了答案,但 android 设备存在一些问题。
这是我在client/templates/categories/cat_list.js中的代码(该项目也在github上:https://github.com/balibou/wali):
感谢您的帮助:)(我尝试过使用"流星添加HTTP",但它真的是一团糟......
Template.catList.helpers({
categories: function() {
return Categories.find();
}
});
Template.catList.events({
"click .toggle-checked": function () {
// Set the checked property to the opposite of its current value
Categories.update(this._id, {$set: {checked: ! this.checked}});
var jsonData = ''+
'{"ApiKey": "544bf635-7f4c-4fb5-9fbe-88116a2dddd5", '+
' "SearchRequest": { '+
' "Keyword": "'+ this.title + '", '+
' "SortBy": "relevance", '+
' "Pagination": { '+
' "ItemsPerPage": 5, '+
' "PageNumber": 0 '+
' }, '+
' "Filters": { '+
' "Price": { '+
' "Min": 0, '+
' "Max": 400 '+
' }, '+
' "Navigation": "computers", '+
' "IncludeMarketPlace": false, '+
' "Brands": [ "asus" ], '+
' "Condition": null '+
' } '+
' } '+
'} ';
console.log(this.title);
$.ajax({
type: "POST",
url: "https://api.cdiscount.com/OpenApi/json/Search",
data: jsonData
}).done(function( msg ) {
console.log(msg)
$("#results").html(
'<div class="product">'+
' <h3>'+msg.Products[0].Name+'</h3>'+
' <img src="'+msg.Products[0].MainImageUrl+'">'+
'</div>'
);
});
},
});
我对你的回答是沟阿贾克斯!如果你想使用meteor,你必须使用Meteor HTTP... http://docs.meteor.com/#/full/http_call
阅读文档时,请更熟悉它。此外,您还需要选择是要使用客户端还是服务器端调用。这里有一些HTTP函数可以帮助您入门:
Template.catList.events({
"click .toggle-checked": function () {
HTTP.call("POST", "https://api.cdiscount.com/OpenApi/json/Search", jsonData);
}
});
相关文章:
- 使用AngularJS$http.get在滚动时重复请求JSON数组
- HTTP Post请求json数据更改
- AJAX请求json失败
- jQuery:请求JSON信息时如何切换大小写
- 如何在 angularjs 中的简单获取请求 json 之后添加事件侦听器
- 客户端通过JS请求JSON并填充Rails视图
- 请求 JSON 时获取“未定义不是一个函数”
- jquery $.ajax 的 MVC 3 反序列化请求 json 到对象中填充空值而不是空白字符串
- 如何使用 Meteor 从 API 导入 http 请求(JSON 格式)
- HTTP请求JSON:意外.解析错误-如何消除它
- 请求JSON加载到Javascript对象中.回应上的差异
- 从服务器请求JSON并用Javascript进行解析
- JSON POST请求-JSON数据,如何使用JSON格式的数据进行POST请求
- 从http页面向https服务器请求json资源
- 通过nodejs从客户端请求JSON数据
- 从html表单传递变量,google图表ajax请求json数据
- 从服务器请求JSON对象
- 来自后端服务的主干请求json(跨域)
- Jquery ajax请求json抛出解析错误
- HTTP GET请求JSON响应- REST API