我正在尝试使用iron-ajax,但是content-type ='application/json'不支持。
<iron-ajax id="ajaxRequestOtp"
method="POST"
url="[[apiEndPoint]]/user-sms-auth"
body="{{requestOtpBody}}"
handle-as="json"
headers='{"Accept": "application/json"}'
on-response="_responseRequestOtp"
on-error="_errorResponseRequestOtp"
content-type='application/json'>
</iron-ajax>
属性 -
static get properties() {
return {
apiEndPoint: {
type: String,
value: 'http://example.com'
},
requestOtpBody: {
type: String,
computed: '_createRequestOtpBody(mobileNumber)',
notify: true
}
};
}
计算功能 -
_createRequestOtpBody(mobileNumber) {
let body = {
phone_number: "+91" + mobileNumber
}
return JSON.stringify(body);
}
这不起作用,404不良要求。我需要将JSON对象发送到我的服务器。
错误消息 -
OPTIONS http://example.com/user-sms-auth 404 (Not Found)
(index):1 Failed to load http://example.com/user-sms-auth: Response for preflight has invalid HTTP status code 404
制作requestOtpBody
=> type: Object
,然后跳过JSON.stringify
步骤。
_createRequestOtpBody(mobileNumber) {
return { phone_number: "+91" + mobileNumber };
}