jquery how to check response type for ajax call

后端 未结 5 735
孤街浪徒
孤街浪徒 2020-12-04 13:57

How can I determine the response type of ajax call in Jquery? At times, the server sends json response and at times it sends only the html for display purposes. Right now I

5条回答
  •  半阙折子戏
    2020-12-04 14:49

    The answers above didnt work for me so I came up with this solution:

    success: function(data, textStatus , xhr) {
    if(xhr.responseXML.contentType == "text/html") {
        //do something with html
        }
    else if(xhr.responseXML.contentType == "application/json") {
        //do something with json
        }}
    

提交回复
热议问题