Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Getting CORS error-No 'Access-Control-Allow-Origin' header is present
#3

(07-20-2018, 08:40 AM)InsiteFX Wrote: Cross-Origin Resource Sharing (CORS)

I was get errorsĀ  on fonts and had to add this to the .htaccess file.

Code:
# Add Font Types
AddType application/vnd.ms-fontobject .eot
AddType font/truetype .ttf
AddType font/opentype .otf
AddType font/opentype .woff
AddType font/opentype .woff2
AddType image/svg+xml .svg .svgz

<FilesMatch ".(eot|ttf|otf|woff|woff2|svg|svgz)">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>

Fixed it. It was not the issue with access control but stupid js was showing error for it.
It was actually happening because I was doing post request using axios and the data I was passing to the ajax request was a js object. It was needed to be stringified using the qs.stringify method. I did it and it got fixed.

Btw, I am using vue js for this app. And here is my final code

Code:
this.$axios({
                        method:'post',
                        url:'http://localhost/hmvc/user/insert',
                        responseType: 'json',
                        data: this.$qs.stringify(vm.formdata)
                    })
                    .then((response)  =>  {
                        console.log(response.data);
                    }, (error)  =>  {
                        console.log(error);
                    });
Reply


Messages In This Thread
RE: Getting CORS error-No 'Access-Control-Allow-Origin' header is present on the request - by aslamdoctor - 07-20-2018, 09:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB