我想张贴在WordPress的通过我的API应用程序离子的注释,但它说,错误401(非法),这意味着WordPress的API认为我没有登录..beforesend的打字稿相当于在Javascript
我的代码:
postComment(params?: any) {
let nonce = localStorage.getItem('nonce');
let seq = this.api.post('wp', 'comments', "post="+ params.post+ "&author_name="+params.author_name+"&author="+params.author+"&[email protected]&content=something").share();
seq
.map(res => res.json())
.subscribe(res => {
}, err => {
console.error('ERROR', err);
});
return seq;
}
在我的研究是说我需要发送的随机数,我可以做这样的:
.ajax({
url: wpApiSettings.root + 'wp/v2/posts/1',
method: 'POST',
beforeSend: function (xhr) {
xhr.setRequestHeader('X-WP-Nonce', wpApiSettings.nonce);
},
data:{
'title' : 'Hello Moon'
}
}).done(function (response) {
});
如何在打字稿中做到这一点?如何在打字稿中放入beforeSend函数xhr.setRequestHeader?
只要是明确的 - 这是一个角度与jQuery的区别,而不是一个打字稿与JavaScript的差异, –