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

300
Visualizações
Access the URL of an jQuery Ajax Request in the Callback Function

Is there a way that I can see the URL that was requested when I do an Ajax request with jQuery?

e.g.,

var some_data_object = { ...all sorts of junk... }
$.get('/someurl.php',some_data_object, function(data, textStatus, jqXHR) {
   var real_url = ? # <-- How do I get this
})

How can I access the URL that jQuery actually used to make the request? Perhaps some method/property of jqHXR? I couldn't find it in the documentation.

Thanks.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Set a break point in success method, then watch

this.url

is the real url for the request.

over 4 years ago · Santiago Trujillo Relatório

0

Here is a possible solution:

  1. Catch the ajax call before it is sent to the server by implementing the beforeSend callback function.
  2. Save the url and the data
  3. Report it in the error message you generate.

    var url = "";
    
    $.ajax({
      url: "/Product/AddInventoryCount",
      data: { productId: productId, trxDate: trxDate, description: description, reference: reference, qtyInCount: qtyInCount }, //encodeURIComponent(productName)
      type: 'POST',
      cache: false,
      beforeSend: function (jqXHR, settings) {
        url = settings.url + "?" + settings.data;
      },
      success: function (r) {
        //Whatever            
      },
      error: function (jqXHR, textStatus, errorThrown) {
        handleError(jqXHR, textStatus, errorThrown, url);
      }
    });
    
    function handleError(jqXHR, textStatus, errorThrown, url) {
       //Whatever
    }
    
over 4 years ago · Santiago Trujillo Relatório

0

Using $.ajaxPrefilter:

// Make sure we can access the original request URL from any jqXHR objects
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
  jqXHR.originalRequestOptions = originalOptions;
});

$.get(
  'http://www.asdf.asdf'
).fail(function(jqXHR){
  console.log(jqXHR.originalRequestOptions);
  // -> Object {url: "http://www.asdf.asdf", type: "get", dataType: undefined, data: undefined, success: undefined}
});

http://api.jquery.com/jQuery.ajaxPrefilter/

over 4 years ago · Santiago Trujillo Relatório
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