Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
Making an Ajax call with both url and query parameters

I have a simple endpoint in flask like the below.

@ns.route ('/cars/<string:make>/<string:model>')

class CarClass (Resource):
    def get (self, make):
        year=request.args.get ('year', type=int)
        website=request.args.get ('website', type=path)
        # do something

Important points to consider are as follows

  1. URL Parameters introduced to illustrate that these are mandatory parameters and the order matters
  2. Query Parameters introduced to illustrate that there are optional parameters (with no relevant ordering)
  3. Website Parameter introduced to illustrate complications with forward slashes and the need to encode paths

When making the API call I think I can pass the query parameters through the data portion, but I am forced to manual create the URL and make an ajax call, like so

url = `https://example.com/cars/${make}/${model}`

try
{
    data = await $.ajax({
    type: 'GET',
    url: url,
    data: JSON.stringify({
        year: year,
        website: website
    }),
    datatype: 'json',
    contentType: 'application/json; charset=utf-8'
    });
}

Is there a builtin Ajax way of passing URL parameters or must I resort to such string manipulation of the URL?

Background: I find the majority of answers to my question simply tell the coder to put the parameters into an object and pass it to data, but when I do this I get a 404 error because the API is looking for /cars/<make>/<model> not /cars

  • How to pass parameter in AJAX URL?
  • How to pass parameters in GET requests with jQuery
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda