Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
Acceda a la URL de una solicitud jQuery Ajax en la función de devolución de llamada

¿Hay alguna manera de que pueda ver la URL que se solicitó cuando realicé una solicitud de Ajax con jQuery?

p.ej,

 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 })

¿Cómo puedo acceder a la URL que jQuery realmente usó para realizar la solicitud? ¿Quizás algún método/propiedad de jqHXR ? No pude encontrarlo en la documentación.

Gracias.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Establezca un punto de quiebre en el método de éxito, luego mire

 this.url

es la URL real de la solicitud.

over 4 years ago · Santiago Trujillo Report

0

Aquí hay una posible solución:

  1. Captura la llamada ajax antes de que se envíe al servidor implementando la función de devolución de llamada beforeSend.
  2. Guarda la url y los datos
  3. Repórtalo en el mensaje de error que generes.

     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 Report

0

Usando $.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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!