Home > Web Front-end > JS Tutorial > body text

Solutions to problems encountered during vue resource post requests

小云云
Release: 2018-01-05 14:55:17
Original
2484 people have browsed it

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);
Copy after login

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'}
}
Copy after login

or use the simpler method provided by vue:

Vue.http.options.emulateJSON = true;
Copy after login

Related recommendations:

php curl get post request usage example sharing

How to solve the problem of vue integrated axios sending post request payload causing the background to be unable to receive data

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!