views:

29

answers:

2

I have the code:

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

Is there a way, to fetch the url it used to make the request after the request has been made(in the callback or otherwise)?

I would want the output:

http://www.example.org?a=1&b=2&c=3
+1  A: 

I can't get it to work on $.get() because it has to complete event.

I suggest to use $.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

Reigel
So smart! I'm surprised this.url isn't available in the success callback
Christopher
A: 

Don't forget that $.get can't do cross-domain ajax request too.

Chouchenos
absolutely, lucky for me, in my situation that doesn't matter :)
Christopher