score:4
Accepted answer
Solution
After days of searching, I came up with a solution. Hopefully it will help someone.
All you need to do is add this two lines to php file:
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Headers: Content-Type');
And in axios request you dont need to use headers, so it can looks like this:
axios.post("your_url", {
your_data
})
.then((response) => {
}, (error) => {
});
Source: stackoverflow.com
Related Query
- CORS error when posting request in React app to PHP file in Apache server on localhost
- CORS issue making AJAX request from React app > Node server > redirect to Google OAuth2 auth
- When attempting to stub a request in Cypress IO (JS) against a React app using fetch, the requests still call through to the server
- File not found error when trying to 'fetch' json in React App
- CORs error AFTER deploying React App and separate Node API to production Unbuntu server where React static files are servered with NGINX
- CORS policy: The 'Access-Control-Allow-Origin' problem when deployed NextJS app on Nginx server tries GET request to local Express server
- 403 Forbidden Error when trying to post and put a axios request in a web app using Django and React
- CORS Error when React App tries to connect via SignalR to .NET CORE Web App having Windows Authentication enabled
- When uploading React app to server all routes except "/" return Internal Server Error
- Having a null violation error when posting from my frontend to the server side in node.js and react and sequelize
- How to fix CORS error when running the React app on Android emulator?
- 503 error when trying to upload image file on deployed react client & express server, followed by CORS error
- CORS error when sending a request from my reactjs app to my express server, which redirects to Spotify's API
- POST request error throwing 404 with node.js server and react app
- How to bypass CORS error when sending POST request to Google Drive API from react application?
- How to deploy a React App on Apache web server
- Error when deploying react app and it keeps sayings << Plugin "react" was conflicted between "package.json » eslint-config-react-app » >>
- Getting an "Access Denied" error when I reload my React app on AWS Amplify
- You need to enable javascript to run this app response when try to access local json file in react
- React app runs locally, crashes when on Heroku error code=H10
- React Axios - C# WebAPI request token fails without a server error
- Getting 403 ACCESS DENIED error when deploying React Web app on AWS Amplify
- CORS error when connecting local React frontend to local Spring Boot middleware application
- eslint error on deployment on local server of react web app
- eslint error on deployment on local server of react web app
- React app returning 500 Internal Server Error
- 404 Error when deploying React App on custom domain
- CORS error on httpsCallable firebase in Create React App
- I'm trying to download a pdf file from a node server to a react client but when I open it, it shows blank
- Error when running jest on a react native + typescript app (Jest encountered an unexpected token)
More Query from same tag
- React Navigation TabNavigator: Reset previous tab on tab change
- Material-UI Tabs inside AutoComplete popover
- ReactJS receiving empty array from NodeJS
- ReactJS - Uncaught Error: Syntax error, unrecognized expression
- What is the correct type for p5.js
- Pros and Cons of React/ JSX method definitions
- Do useSelector() and useDispatch() replace mapStateToProps() and mapDispatchToProps()?
- Change rendered components depending on state
- How can I re-fetch an API using react hooks
- with react final-form why is meta.touched always false with third party components?
- Multiple Select not working, only giving last clicked value
- TSX file can't render imported React Component
- Get element was clicked in react using ref
- Setting value in a react-dropdown Dropdown's onChange callback throws an error
- How to check instance of key which is present inside object
- What is the best way to filter data in React?
- React Hooks Form not returning values on submit
- Why datepicker flicker in React when focus in input field?
- How is React's Virtual DOM faster than DOM?
- React possible to change scss variable?
- React Hooks (Functional) Lifecycle: Component rendered before useEffect() code
- React: flattenChildren(...): Encountered two children with the same key
- How to call Meteor.call inside a react component on the client?
- React Bootstrap NavBar Container, set width to auto
- Unable to parse data from react firebase object
- React es5 vs es6
- React + Redux + Firebase: how to deal with a firebase configuration defined and exported as a class?
- React: Don't render components in table who aren't visible
- Make compass in React-Native
- React Typescript Functional Component Syntax Error