我正在使用Polymer 1.7.0。如何在<iron-form>
中发送请求标头?
我试过了:
form.addEventListener('iron-form-presubmit', function(event) {
var headers = {'akash':'akash'};
event.target.request.requestHeaders = headers;
console.log(event.target.request.requestHeaders);
});
记录了以下文本,但我的标题未出现在请求中。
console.log(event.target.request.requestHeaders);
==&gt; "Object {content-type: "application/x-www-form-urlencoded"}"
答案 0 :(得分:0)
<iron-form>.request
属性为<iron-ajax>
,而<iron-ajax>.requestHeaders
实际上不是属于可设置属性。请改用<iron-ajax>.headers
属性
form.addEventListener('iron-form-presubmit', function(event) {
var headers = {'akash':'akash'};
event.target.request.headers = headers;
});
答案 1 :(得分:0)
我们可以使用以下两种方式添加标题:
<form is="iron-form" id="form"
method="POST" action="/"
on-iron-form-response="responseHandler"
on-iron-form-error="errorHandler"
headers = '{"akash":"akash"}'>
<template>
<content></content>
<div class="layout vertical parent-style">
<form is="iron-form" id="form"
method="POST" action="/"
on-iron-form-response="responseHandler"
on-iron-form-error="errorHandler">
</form>
</div>
`
function handleLoginAction(event)
{
var form = Polymer.dom(event).localTarget.parentElement.parentElement; // Get Form ref from DOM.
form.headers = "{'akash':'akash'}";
form.submit();
}
form.addEventListener('iron-form-presubmit', function(event) {
console.log("Headers--------------");
console.log(event.target.request.requestHeaders); // {'akash':'akash'}
});
</script>
</template>`