axios

Cant cancel Axios post request via CancelToken

坚强是说给别人听的谎言 提交于 2019-12-01 06:01:35
This code cancel GET requests but cant abort POST calls. If i send GET requests first and i dont cancel them via abortAll method,they just finish by themselves this token cancel by itself and doesnt work on next requests? What am i missing? Thanks,John import axios from 'axios' class RequestHandler { constructor(){ this.cancelToken = axios.CancelToken; this.source = this.cancelToken.source(); } get(url,callback){ axios.get(url,{ cancelToken:this.source.token, }).then(function(response){ callback(response.data); }).catch(function(err){ console.log(err); }) } post(url,callbackOnSuccess

Uploading files with VueJS, axios and Laravel

别等时光非礼了梦想. 提交于 2019-12-01 05:17:06
问题 Hello I am building one project. Where user can send up to 5 images and up to 10 songs with the text. But when I send request to the server, where I handle with Laravel, I can't get those files. // my data object from VueJS data() { return { formData: new FormData(), pikir: { body: '', }, isLoading: false, images: [], songs: [], } } // imagePreview method from VuejS imagePreview(event) { let input = event.target; if (input.files[0]) { if (input.files.length <= 5) { for (let i = 0; i < input

How to send a file via Axios to Laravel

心已入冬 提交于 2019-12-01 04:28:49
I need to post a File from client to server via Axios. Here is my Vuejs code : methods: { 'successUpload': function (file) { const config = { headers: { 'Content-Type': 'multipart/form-data' } }; axios.post('/Upload/File',file, config).then(function (response) { console.log(response.data); }); } } And here is my Laravel code for handling sent file : public function uploadFile(Request $request) { if($request->hasFile('file')) return "It's a File"; return "No! It's not a File"; } But it always returns No It's not a File . Any helps would be great appreciated. You have to create a FormData object

Flask-CORS not working for POST, but working for GET

ぃ、小莉子 提交于 2019-12-01 04:15:23
I'm running a Flask-Restful API locally and sending a POST request containing JSON from a different port. I'm getting the error No 'Access-Control-Allow-Origin' header is present on the requested resource. However, when I run curl --include -X OPTIONS http://localhost:5000/api/comments/3 --header Access-Control-Request-Method:POST --header Access-Control-Request-Headers:Content-Type --header Origin:http://localhost:8080 I get HTTP/1.0 200 OK Content-Type: text/html; charset=utf-8 Allow: HEAD, GET, POST, OPTIONS Access-Control-Allow-Origin: http://localhost:8080 Access-Control-Allow-Methods:

Axios call api with GET become OPTIONS

て烟熏妆下的殇ゞ 提交于 2019-12-01 02:36:18
问题 I use axios for calling API (in front-end). I use the method "GET" : import axios from 'axios'; import querystring from 'querystring'; var url = "mydomain.local", token = "blablabla...blabla"; var configs = { headers: { 'Authorization': 'Bearer ' + token, 'Agency': 'demo0' } }; var testapi = axios.create({ baseURL: 'http://api.' + url }); testapi.get( '/relativeUrl', configs ).then(function (response) { console.log(response); }).catch(function (error) { console.log(error); }); I got a 405

How to send a file via Axios to Laravel

风流意气都作罢 提交于 2019-12-01 02:29:07
问题 I need to post a File from client to server via Axios. Here is my Vuejs code : methods: { 'successUpload': function (file) { const config = { headers: { 'Content-Type': 'multipart/form-data' } }; axios.post('/Upload/File',file, config).then(function (response) { console.log(response.data); }); } } And here is my Laravel code for handling sent file : public function uploadFile(Request $request) { if($request->hasFile('file')) return "It's a File"; return "No! It's not a File"; } But it always

POST file along with form data Vue + axios

佐手、 提交于 2019-11-30 22:27:47
I have a method for Vuejs component: async submit () { if (this.$refs.form.validate()) { let formData = new FormData() formData.append('userImage', this.avatarFile, this.avatarFile.name) this.avatarFile = formData try { let response = await this.$axios.post('http://localhost:3003/api/test.php', { avatar: this.avatarFile, name: this.name, gender: this.gender, dob: this.DOB, }, { headers: { 'Content-Type': 'multipart/form-data; boundary=' + formData._boundary } }) if (response.status === 200 && response.data.status === 'success') { console.log(this.response) } } catch (e) { console.log(e) } } }

axios interceptors response undefined

穿精又带淫゛_ 提交于 2019-11-30 22:17:29
I'm trying to logout my user once they get a 401. I'm using axios to return data from the api I was looking around and found the same axios.interceptors.response axios.interceptors.response.use( response => response, error => { const {status} = error.response; if (status === 401 ) { store.dispatch('snackBar', snackbarObj) } return Promise.reject(error); } ) It appears my error.response is undefined. I'm not sure what is wrong? any ideas? You're not getting a response from the request you're doing with Axios since the browser received a 401 unauthorized response when doing the preflight OPTION

JavaScript中发出HTTP请求最常用的方法

荒凉一梦 提交于 2019-11-30 18:28:24
JavaScript中发出HTTP请求最常用的方法 JavaScript具有很好的模块和方法来发送可用于从服务器端资源发送或接收数据的HTTP请求。在本文中,我们将介绍一些在JavaScript中发出HTTP请求的流行方法。 Ajax Ajax是发出异步HTTP请求的传统方式。可以使用HTTP POST方法发送数据,并使用HTTP GET方法接收数据。我们来看看发送GET请求。我将使用JSONPlaceholder,这是一个免费的在线REST API,适用于以JSON格式返回随机数据的开发人员。 要在Ajax中进行HTTP调用,您需要初始化一个新XMLHttpRequest()方法,指定URL端点和HTTP方法(在本例中为GET)。最后,我们使用该open()方法将HTTP方法和URL端点绑定在一起,并调用该send()方法来触发请求。 我们使用XMLHTTPRequest.onreadystatechange包含要在readystatechanged事件触发时调用的事件处理程序的属性将HTTP响应记录到控制台。 如果您查看浏览器控制台,它将返回JSON格式的数据数组。但是我们怎么知道请求是否完成了?换句话说,我们如何使用Ajax处理响应? 该onreadystatechange有两个方法,readyState 和 status允许我们可以检查请求的状态。

VUE 利用axios请求接口

旧巷老猫 提交于 2019-11-30 18:07:30
跨域问题 开发环境 找到config文件夹下面的index.js文件,修改proxyTable //config 下的index.js proxyTable: { '/api': { //使用"/api"来代替"http://f.apiplus.c" target: 'https://www.baidu.com', //接口的域名 secure: true,// 如果是https接口,需要配置这个参数 changeOrigin: true, // 如果接口跨域,需要进行这个参数配置,为true的话,请求的header将会设置为匹配目标服务器的规则(Access-Control-Allow-Origin) pathRewrite: { '^/api': '' //本身的接口地址没有 '/api' 这种通用前缀,所以要rewrite,如果本身有则去掉 } } , }, host: '10.16.101.136', // can be overwritten by process.env.HOST port: 8071, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined autoOpenBrowser: false,//是否自动打开浏览器