8

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.

1 Answer 1

11
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>

Sign up to request clarification or add additional context in comments.

1 Comment

Ha! Missed it! In the beforeSend(jqXHR, settings) callback. Thanks @Lee.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.