wayfarer_boy wayfarer_boy - 11 months ago 63
jQuery Question

Logging the constructed URL string in a jQuery.ajax() GET request

I'm wanting to log the fully constructed url string of a jQuery.ajax call.I'm setting the params in the data variable of the ajax command, like so:

jQuery.ajax({
url: 'http://a.site.com',
data: {
format: 'json',
name: 'John Smith',
addressdetails: 1
},
beforeSend: function(jqXHR, settings) {
console.log(jqXHR, settings); // Can't find it in these values
},
success: function(data, textStatus, jqXHR) {
console.log(data, textStatus, jqXHR); // Nor in these
}
});


What I would be looking for in the logs from the example above is this string:

'http://a.site.com?format=json&name=John%20Smith&addressdetails=1'


I feel like there must be something I'm missing. I'm convinced it will be in one of the callback functions, but can't for the life of me find it anywhere. Any help appreciated.

Lee Lee
Answer Source
settings.url

See snippet:

$.ajax({
  url: 'http://google.com',
  data: {
    format: 'json',
    name: 'John Smith',
    addressdetails: 1
  },
  beforeSend: function(jqXHR, settings) {
    document.write(settings.url);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download