With the following jQuery.ajax response...
{"ysearchresponse":
{"responsecode":"200","totalhits":"0","deephits":"0","count":"0","start":"0"}}
How d开发者_StackOverflow中文版o I do a comparison on "totalhits" in order to execute the error: function() when totalhits == "0" ?
You can't. (see first comment). And trust me, you don't want to. The error callback is meant for errors related to the ajax request and not for errors only you consider errors (i.e. nonsense data which is valid json/xml/whatever or an empty resultset).
However, if you want your error function called, create it as a regular (named) function instead of an anonymous one and call it manually when your criteria are met. Note that making your function a regular one results in it not being a closure anymore - but without seeing your full $.ajax(...);
call and some surrounding code it's impossible to tell if that'll be a problem or not.
精彩评论