如何根据响应调用更改ajax url

时间:2013-11-20 13:47:33

标签: javascript php jquery

如何根据回复调用更改ajax url

$.ajax({
    url: "/url/1/1",
    dataType: "json",
    success: function (response) {
        if (response) {
            // i want to change url based on response
            //example var next = response.next    
            // den i want to call url as /url/1/next.
        }
    }
});

2 个答案:

答案 0 :(得分:0)

$.ajax({
    url: "/url/1/1",
    dataType : "json"
}).done(function(response) {
    if ('next' in response) {
        document.location.href = '/url/1/' + response.next;
    }
});

答案 1 :(得分:0)

 $.ajax(
    {
            url: "/url/1/1",
            dataType : "json",
            success: function(response) 
            {
                    if(response)
                    {
                       // i want to change url based on response
                       //example var next = response.next    
                       // den i want to call url as /url/1/next.
              -----------------after response----------    
                var next = response.next
                    $.ajax(
                       {
                           url: "/url/1/"+next,// you can set like this
                          dataType : "json",
                        success: function(response) 
                            {.....
                       }
                        });
                 -------------------------------------

                    }
            }
     });