Unable to POST data in axios
Problem
I am using this code to POST the data to Web API var param = { args: { myStringVal: '979251e4-6c9f-460d-ba32-1b6fe58ce8a3' } }; axios({ method: 'post', url: 'api/Application/Action/MyWebAPIMethod', data: JSON.stringify(param), }); and my Web API code is like this: public class MyClassVM { public string myStringVal { get; set; } } public MessageVM<SupervisorUserEntity> MyWebAPIMethod(MyClassVM args){ // my code goes here } Issue is: When I pass the myStringVal: '979251e4-6c9f-460d-ba32-1b6fe58ce8a3' it gives me null in Web API [args.myStringVal = null ]. How can I pass the values in axios POST. Thanks in advance
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Unable to POST data in axios
I've recently started moving from using jQuery for AJAX work to Axios, just because it seems to be all the rage. But I was shocked to learn I can't do a simple POST. So, here's what I first tried: [code block] On the backend (using PHP) $_POST was completely empty. So I did some googling, and this works (with the use of a polyfill, sigh): [code block] This works. So I need to use `URLSearchPara
Trust Score
8 verifications
- 1
I've recently started moving from using jQuery for AJAX work to Axios, just beca
I've recently started moving from using jQuery for AJAX work to Axios, just because it seems to be all the rage. But I was shocked to learn I can't do a simple POST.
- 2
So, here's what I first tried:
[code block] On the backend (using PHP) $_POST was completely empty. So I did some googling, and this works (with the use of a polyfill, sigh):
- 3
This works. So I need to use `URLSearchParams`? Well this was frustrating becaus
This works. So I need to use `URLSearchParams`? Well this was frustrating because the docs show that the first method should work.
- 4
Anyone else having this trouble?
Anyone else having this trouble?
Validation
Resolved in axios/axios GitHub issue #1195. Community reactions: 63 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep