How to explain the backend developer why can't I do what he wants?

Question I already asked. But I will repeat it again

There is a piece of code
'formData.brand'(val) {
 let payload = {
 names: arr,
 values: {
 "brand": val
}
}
 if (!val) return;
 axios.get('../../../json/v1/form/CASCO/dependencies', {
 params: payload
 }).then(response => {
 this.$set(this.dependentData, 'brand', {
 model: response.data.models,
 country: response.data.city
});
 }).catch(errors => {
console.error(errors);
});
}


in values to give the object
On Beck comes line; Becker requires, that he came to the object
5b51acdd1e1ee358756848.png

Sent this screenshot to me
5b51aceaa1d2e624263030.png
How to explain to him normal that I can't do what he wants?
June 3rd 19 at 19:31
4 answers
June 3rd 19 at 19:33
Solution
Learn the techniques of queries. With GET you send a string to send the object you need to use one of POST, PUT, PATCH and the object to send a parameter
https://developer.mozilla.org/uk/docs/Web/HTTP/Methods
https://learn.javascript.ru/ajax-xmlhttprequest
https://developer.mozilla.org/en-US/docs/Web/API/F...
Tovi piece of code
axios.get('../../../json/v1/form/CASCO/dependencies', {
 params: payload
 }).then(response => {


A piece of code from the documentation
Performing a POST request
axios.post('/user', {
 firstName: 'Fred',
 lastName: 'Flintstone'
})
 .then(function (response) {
console.log(response);
})
 .catch(function (error) {
console.log(error);
 });


Teach backend API to write the contract in https://swagger.io/ TOD will be less misunderstandings
Yes, there is that on the front of that buck - people who slightly understand what's going on. In place of the author I would look through the network tab in the devtools would be an example that goes to the back. And compared with what goes to him.

RS: I'm tired of the history of this most ill-fated array (already three weeks lasts :) ) - Dahlia.Swi commented on June 3rd 19 at 19:36
so I understand that I can't send object - rowan43 commented on June 3rd 19 at 19:39
the question wasn't it :) - rowan43 commented on June 3rd 19 at 19:42
And as http to send the object, unless it is a text Protocol? - marilyne_Roh commented on June 3rd 19 at 19:45
well the number you can send, and the number is not text, and hence the object. (sarcasm) - Edwin.Abbo commented on June 3rd 19 at 19:48
as a text and as an int - no - marilyne_Roh commented on June 3rd 19 at 19:51
You have in the code axios.get or you're not too understand what you are doing or you and Beck don't understand if he's having the IPA contract must be of get, because get is used to retrieve data, not to send.
Use POST, PUT, PATCH, I brought you a piece of code. - Isaias_Medhurst commented on June 3rd 19 at 19:54
Learn the techniques of queries. With GET you send a string to send the object you need to use one of POST, PUT, PATCH


You might learn some ;)
Every HTTP request sends the row. This is a text Protocol.
Php is already in its bosom the machine converts the parameters into arrays $_GET, $_POST, and others. - Lulu_Zulauf71 commented on June 3rd 19 at 19:57
OK , I didn't mean it. Sending the request via GET, you get
1) Limitation on query length
2) Percent-encoding your structures
In addition to not according to specifications - Isaias_Medhurst commented on June 3rd 19 at 20:00
well at least I quoted part of the text was presented in the form of contrasting one another. - Lulu_Zulauf71 commented on June 3rd 19 at 20:03
June 3rd 19 at 19:35
Solution
1. in JS associative array and the object are one and the same in PHP -no.
2. an object in JS is JSON format, PHP JSON is a string
3. GET can only pass a string that PHP can interpret as an array or as an array of arrays, but any object in a Protocol is not provided. In the comments wrote that in principle, you can pass an object as a JSON string.stringify(myObj); but buck it we must again decode.

But the problem I see is not in this, buck's apparently want to get an array and not an object as you put it, just as if you had sent the form data Room, and to get such a string as in the screenshot with parse_str really a perversion
June 3rd 19 at 19:37
You can do so, as backender.
The problem is Axios. GET parameters if they contain multi-dimensional arrays/objects it converts to json representation, leaving only line the top-level array. In General, the right (it is said ), GET to query data, and query parameters usually go with a list.
But the Protocol allows to introduce and arrays, both linear and multidimensional. jQuery, by the way, in this sense, does so.

In General, to the point. You can use standard features Axios to transform query parameters:

let arr = [1,2,3];
let val = 'BMW';
let payload = {
 names : arr,
 values: {
 brand: val,
},
};

axios.get('http://site.ru?id=1', {
 params: payload,
 paramsSerializer: function(params) {
 let tmp = [];
 params.names.forEach(item => {tmp.push(`names[]=${item}`)});
 for (let name in params.values) {
 if (!params.values.hasOwnProperty(name)) continue;
tmp.push(`values[${name}]=${params.values[name]}`);
}
 return tmp.join('&');
},
}).then( ...


In the result of a query the programmer will receive data in the array &_GET about like this:

Array
(
 [id] => 1
 [names] => Array
(
 [0] => 1
 [1] => 2
 [2] => 3
)
 [values] => Array
(
 [brand] => BMW
)
)


The serializer have to write under the format of the data, or try to figure out something versatile.
June 3rd 19 at 19:39
wait, what are you doing? you're sending to backend:
- an array of strings where names - query param and type a GET request, it's OK
- in query param: values which is the object {"brand": "bmw"}, what is this?
of course you can do the following:

const url = '../../../json/v1/form/CASCO/dependencies?values=' 
const values = {
 "brand": val
}

axios.get(url + JSON.stringify(values))
 .then(response => {....})
 .catch(...);


how to form a loop in the line ?names[]=models&names[]=oiltype think I can guess, it will need to also add a url variable.

if the data is to create a new row in some table leaves, then I'd rather send axios'th in the backend a post request with data and content-type: application/json
something like:

data = {
 "names": [{
 "models": [{"brand" "bmw"}]
}]
}

Find more questions by tags Vue.js