jQuery and AJAX response header

前端 未结 8 2537
夕颜
夕颜 2020-11-22 10:45

So I\'ve got this jQuery AJAX call, and the response comes from the server in the form of a 302 redirect. I\'d like to take this redirect and load it in an iframe, but when

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 10:57

    UPDATE 2018 FOR JQUERY 3 AND LATER

    I know this is an old question but none of the above solutions worked for me. Here is the solution that worked:

    //I only created this function as I am making many ajax calls with different urls and appending the result to different divs
    function makeAjaxCall(requestType, urlTo, resultAreaId){
            var jqxhr = $.ajax({
                type: requestType,
                url: urlTo
            });
            //this section is executed when the server responds with no error 
            jqxhr.done(function(){
    
            });
            //this section is executed when the server responds with error
            jqxhr.fail(function(){
    
            })
            //this section is always executed
            jqxhr.always(function(){
                console.log("getting header " + jqxhr.getResponseHeader('testHeader'));
            });
        }
    

提交回复
热议问题