jquery how to check response type for ajax call

后端 未结 5 740
孤街浪徒
孤街浪徒 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:42

    You can simply use javascript's easy method to check the type

    i.e.

    if(typeof response=="object")
    {
     // Response is javascript object
    }
    else
    {
     // Response is HTML
    }
    

    If you use this method you don't have to write 2 extra parameter in the success callback.

提交回复
热议问题