admin管理员组文章数量:1278976
N.B. Resolved - I hadn't noticed it was a POST rather than a GET.
I'm trying to use an AJAX call from a front end page to pull a list "Staff" (custom post type). I can get the data in the browser via wp-json/wp/v2/staff but I get a 401 when I try to pull the data via AJAX. I'm assuming I need to authenticate somehow but can't work out how to to do it.
Thanks in advance.
N.B. Resolved - I hadn't noticed it was a POST rather than a GET.
I'm trying to use an AJAX call from a front end page to pull a list "Staff" (custom post type). I can get the data in the browser via wp-json/wp/v2/staff but I get a 401 when I try to pull the data via AJAX. I'm assuming I need to authenticate somehow but can't work out how to to do it.
Thanks in advance.
Share Improve this question edited Nov 1, 2021 at 9:28 Codescribler asked Oct 27, 2021 at 15:51 CodescriblerCodescribler 1216 bronze badges 8- Have you read the docs? developer.wordpress/rest-api/using-the-rest-api/… – Jacob Peattie Commented Oct 28, 2021 at 7:16
- All those docs talk about making changes on the PHP side. Surely that's not required!? – Codescribler Commented Oct 28, 2021 at 7:19
- Depending on what you’re trying to do, yes it is. Normally custom post type endpoints don’t require authentication, but if that’s been added then you need to follow those steps to ensure your request is authenticated. – Jacob Peattie Commented Oct 28, 2021 at 7:45
- I can explore all the data I need by just going to the wp-jason url I posted above. I could probably scrape it which seems utterly ridiculous. But I can’t get it via Ajax. Something is wrong with that. – Codescribler Commented Oct 28, 2021 at 7:47
- 1 There’s something wrong with your AJAX request then. But there’s no code in your question so it’s not possible to say more. It sounds like you might be sending a POST request instead of GET. – Jacob Peattie Commented Oct 28, 2021 at 7:50
1 Answer
Reset to default 1I had accidentally created a POST rather than a GET. Obviously, you need credentials if you post.
本文标签: I39m getting a 401 while calling the wpjson endpoint via ajax
版权声明:本文标题:I'm getting a 401 while calling the wp-json endpoint via ajax 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741241928a2364149.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论