Vue.js resource, method "post" and "delete" do not work


#1

hi,
look this little project (In the event of an error, allow access origin … use the chrome extension “allow -control-allow-origin”)
So, the method “get” work fine and the data are published ,but post (for addFilm) and delete (for cancellaFim) do not work… please help me, I am becoming crazy… thanks


#2

Your server blocks the request because of CORS.

Access to XMLHttpRequest at ‘https://www.gdrdesign.it/prove/lista/data/film.json’ from origin ‘https://s.codepen.io’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

If you want codepen.io to be able to make requests to your server, you need to adjust the CORS config.


#3

this is not my problem. I also explained … on codepen I can not upload files (film.json) and I had to upload it to my host. If you want to download the project folder here https://mega.nz/#F!io8ghITa!SMxQAxkTNJ-3EO5GNI5l-A. My problem are the method post and delete…


#4

Yes. Because your server blocks the requests because of CORS. Your issue is exactly as I have pointed out.


#5

But no… if you use the extension the date the data is uploaded. download the project that mega and test it locally will see that no error of access allow origin. IT IS NOT MY PROBLEM! uff…


#6

CORS error occurs because I loaded the movie.json file on my host … But my project is locally I’m not interested in resolving that error (which I still solved with the chrome extension)


#7

I see. That wasn’t clear in your post. Your issue is because you aren’t using an API to update your data. You can’t just post/delete to a json file. You need to use an API endpoint on your server. That endpoint then uses a controller to apply the necessary changes to your database (or to update the file, but that’s a very inefficient and potentially messy way of storing data - though MongoDB uses a similar approach but has an entire API).


#8

but with vue resource it is possible to insert or delete records in an array and without API … https://github.com/pagekit/vue-resource


#9

You will need to elaborate because this definitely isn’t possible from the client side. The server handles the request and needs to be instructed on how to handle it.