在jQuery.ajax()GET请求中记录构造的URL字符串

way*_*boy 5 jquery

我想记录jQuery.ajax调用的完全构造的url字符串.我在ajax命令的数据变量中设置params,如下所示:

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
  }
});
Run Code Online (Sandbox Code Playgroud)

我在上面的例子的日志中寻找的是这个字符串:

'http://a.site.com?format=json&name=John%20Smith&addressdetails=1'
Run Code Online (Sandbox Code Playgroud)

我觉得必须有一些我想念的东西.我确信它会在其中一个回调函数中,但不能在我的生活中找到它的任何地方.任何帮助赞赏.

Lee*_*Lee 8

settings.url
Run Code Online (Sandbox Code Playgroud)

请参阅代码段:

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