-1

I'm trying to write a web program in JavaScript where I have to make multiple ajax calls, and I need to figure out how to get the url after making an ajax call to the url. The ajax calls are made in a for loop that loops through an array of urls. So the code for the ajax request and the function that processes the return of the request look something like this:

requester = function(url){
    $.ajax({
        url : "http://url of my proxy?url=" + escape(url),
        type : "GET",
        data-type : "xml"
    }).done(dataProcessor);
};

dataProcessor = function(data){
    //a bunch of code, including things where I must have the url for the ajax request
};

So, how can I get that url?

1
  • Why not function requester(url) { ... }? Commented Nov 14, 2012 at 4:10

3 Answers 3

0

You can simply save it and pass it to your function:

requester = function(url){
    var fullURL = "http://url of my proxy?url=" + escape(url)
    $.ajax({
        url : fullURL,
        type : "GET",
        data-type : "xml"
    }).done(function(data) {dataProcessor(data, fullURL)});
};

dataProcessor = function(data, url){
    //a bunch of code, including things where I must have the url for the ajax request
};
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, thank you!! I wasn't sure how to pass a parameter when a function is called this way because I'm new to web programming, but this makes perfect sense now, and it works! :)
0

Take advantage of closures

requester = function(url){
    $.ajax({
        url : "http://url of my proxy?url=" + escape(url),
        type : "GET",
        data-type : "xml"
    }).done(function(data) {

         alert(url);

    });
};

Comments

-1

It's available from the this value, which is the jqXHR object.

dataProcessor = function(data){
    console.log(this.url);
};

1 Comment

Down-vote on a correct and fast solution?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.