Reputation: 87
I'd like to filter and want to pass an array to the url.
handleFilter = (search, page = 1) => {
const requestOption = {
method: "GET"
};
fetch("http://127.0.0.1:8000/api/home?search=" + JSON.stringify(search) + "&page=" + page, requestOption)
.then(res => res.json())
.then(data => (
this.setState({
data
})
))
};
Just want to pass the array of data to the api to call the query
Upvotes: 2
Views: 84
Reputation: 562
If you want send it exactly as GET method (not Post), you can form your URL like this:
"http://127.0.0.1:8000/api/home?search[]=value1&search[]=value2&search[]=value3"
That is if you don't want send JSON string.
And what the problem with JSON version or POST method?
Upvotes: 0
Reputation: 66
I don't know if this will be what exactly you need, but I would... a.) Join it on a strange character, and pass it as a string. b.) On the receiving side (client or server), split on that same character.
Upvotes: 2