0

I want to add query string to all requests (post and etc) with Jquery or pure Javascript.

for example : domain.com?debug=true I want to when click a button and its Ajax , this query string add.

Thank you in advance for your guidance.

I concluded that this is not a good question

ma ja
  • 333
  • 4
  • 15

1 Answers1

-1

you can use the body property which lets you send data to the server

for example:

    fetch("URLHERE", {
        method: "POST",
        body: JSON.stringify({debug: true}),
        headers: { // this lets you send data in json format
            'Accept': 'application/json, text/plain, */*',
            'Content-Type': 'application/json'
        })
    .then(res => ...)

please note: you need to send the data in string format, thats why i used JSON.stringify

check here for refernce : https://javascript.info/fetch-api

EDIT: DO NOT use body in GET request check here why: HTTP GET with request body

if you want to send data to the server you usually use POST

if you want to get data from the server with get you need to send http request with the url you want and you can also send in with query

for ex: my endpoint is "https://api.getCoolData.com/?debugger=true

and in your server you can take the query part the use it

amir
  • 196
  • 9