简体   繁体   中英

Make an ajax request based on a variable from another ajax request

I have one ajax function that is parsing xml to return the data. Something like :

$.ajax({
    type: "GET",
    url: "the.xml",
    dataType: "xml",
    success:   function  parseXml(data){
        $(data).find("ITEM").each(function(){
            var x= $("URL", this).text();
            $("#content").append('<div>' + (z) + '</div>');
        }); 
    }

Now I need to pass x to a second ajax request before I print it in the content div (the z variable). Can someone please explain to me how this would work. My other request would be something like:

$.ajax({
    type: 'GET',
    url: x,
    data: 'req=exists,json',
    dataType: 'jsonp',
    success: s7jsonResponse
});


function s7jsonResponse(response){
     var z = response["catalogRecord.exists"];
}

Please forgive the mess, I am just trying to get my question across... thanks for any help!

首先在ajax调用之外定义变量,这样您就可以成功更改它(而不是在本地定义),并且该变量可用于其他函数。

您还将希望在第一次调用成功时进行第二次呼叫,并在第二次调用成功时进行追加。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM