How to get request URL in jQuery $ .get / ajax request

I have the following code:

$.get('http://www.example.org', {a:1,b:2,c:3}, function(xml) {}, 'xml'); 

Is there a way to get the URL used to execute the request after the request has been completed (in a callback or otherwise)?

I need a conclusion:

 http://www.example.org?a=1&b=2&c=3 
+27
javascript jquery
Sep 30 '10 at 5:53
source share
2 answers

I cannot get it to work with $.get() because it does not have a complete event.

I suggest using $.ajax() like this,

 $.ajax({ url: 'http://www.example.org', data: {'a':1,'b':2,'c':3}, dataType: 'xml', complete : function(){ alert(this.url) }, success: function(xml){ } }); 

craz demo

+38
Sep 30 '10 at 6:10
source share

Since jQuery.get is just a shorthand for jQuery.ajax, another way would be to use the last context option, as stated in the documentation :

The this link in all callbacks is the object in the context parameter passed in $.ajax in the settings; if no context is specified, this is a link to the Ajax settings themselves.

So you would use

 $.ajax('http://www.example.org', { dataType: 'xml', data: {'a':1,'b':2,'c':3}, context: { url: 'http://www.example.org' } }).done(function(xml) {alert(this.url}); 
+3
Oct 27 '14 at 11:30
source share



All Articles