¿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.
Establezca un punto de quiebre en el método de éxito, luego mire
this.urles la URL real de la solicitud.
Aquí hay una posible solución:
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 }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} });