Home >Web Front-end >JS Tutorial >Solutions to problems encountered during vue resource post requests
This article mainly introduces the pitfalls encountered when requesting vue resource post. Friends in need can refer to it. I hope it can help everyone.
Use post request
// global Vue object Vue.http.get('/someUrl', [options]).then(successCallback, errorCallback); Vue.http.post('/someUrl', [body], [options]).then(successCallback, errorCallback); // in a Vue instance this.$http.get('/someUrl', [options]).then(successCallback, errorCallback); this.$http.post('/someUrl', [body], [options]).then(successCallback, errorCallback);
However, this does not mean that you will not encounter problems during use: (For example, when you encounter such an error: XMLHttpRequest cannot load XXX. Response for preflight has invalid HTTP status code 405); This $http request is still a little different from jquery's ajax. The post data here is not in the form of form data by default, but the request payload. The solution is very simple: add the headers field to the vue instance:
http: { headers: {'Content-Type': 'application/x-www-form-urlencoded'} }
or use the simpler method provided by vue:
Vue.http.options.emulateJSON = true;
Related recommendations:
php curl get post request usage example sharing
How to implement Ajax GET POST request using native JS
The above is the detailed content of Solutions to problems encountered during vue resource post requests. For more information, please follow other related articles on the PHP Chinese website!