Polymer 从Iron Ajax调用检索结果
我开始学习Polymer,尤其是iron ajax,它用于从ASP.NETWebAPI服务检索JSON数据。我可以调用该服务,但无法获取该服务返回的结果 以下是我的铁元素:Polymer 从Iron Ajax调用检索结果,polymer,polymer-1.0,Polymer,Polymer 1.0,我开始学习Polymer,尤其是iron ajax,它用于从ASP.NETWebAPI服务检索JSON数据。我可以调用该服务,但无法获取该服务返回的结果 以下是我的铁元素: <iron-ajax auto url="http://local.webapi2.com/api/values" headers='{ "Key": "d72ad080-e3dd-43ea-ba95-0cd2a5a58bb1" }'
<iron-ajax auto
url="http://local.webapi2.com/api/values"
headers='{ "Key": "d72ad080-e3dd-43ea-ba95-0cd2a5a58bb1" }'
handle-as="json"
content-type="application/json"
method='GET'
verbose="true"
on-response="handleResponse"></iron-ajax>
以下是我的WebAPI端点:
[RoutePrefix("api/values")]
public class ValuesController : ApiController
{
// GET api/values
[Route("")]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2", "value3", "value4", "value5", "value6" };
}
}
但是,在Firebug的控制台中,我只看到以下内容:
response from server: response
其中,“response”是一个对象,似乎是关于“ironajax”元素本身的详细信息。预期结果数据永远不会显示在控制台中。此外,控制台中WebAPI调用的Response选项卡的值为null。控制台中WebAPI调用下的细节中甚至没有JSON选项卡
我不知道为什么Net选项卡会像您所期望的那样具有完整和准确的结果,但是Console选项卡会为空,并且我会看到一个“response”对象
我在Chrome上也遇到了同样的情况
我错过了什么?这是配置问题吗?谢谢您的时间。我实际上也在使用ASP.NET Web API,但没有出现此问题 问题可能出在这条线路上-
handleResponse: function (jsonFromServer)
{
console.log('response from server:', jsonFromServer);
}
aregument不是直接返回值,而是整个事件对象。所以也许可以试试-
handleResponse: function (e)
{
console.log('response from server:', e.detail.response); // or e.detail.xhr.repsone
}
handleResponse: function (jsonFromServer)
{
console.log('response from server:', jsonFromServer);
}
handleResponse: function (e)
{
console.log('response from server:', e.detail.response); // or e.detail.xhr.repsone
}