Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jquery

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.

like image 572
wayfarer_boy Avatar asked Jun 07 '12 15:06

wayfarer_boy


1 Answers

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>
like image 63
Lee Avatar answered Sep 22 '22 08:09

Lee