-1

JavaScriptで複数のajax呼び出しを行う必要があるWebプログラムを作成しようとしていますが、URLに対してajax呼び出しを行った後にURLを取得する方法を理解する必要があります。ajax呼び出しは、URLの配列をループするforループで行われます。したがって、ajaxリクエストのコードとリクエストの戻りを処理する関数は次のようになります。

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
};

では、どうすればそのURLを取得できますか?

4

3 に答える 3

0

クロージャを活用する

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

         alert(url);

    });
};
于 2012-11-14T04:08:59.920 に答える
0

保存して関数に渡すだけです。

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
};
于 2012-11-14T04:10:12.537 に答える
-1

オブジェクトthisである値から利用できます。jqXHR

dataProcessor = function(data){
    console.log(this.url);
};
于 2012-11-14T04:10:27.007 に答える