Jquery Ajax中的Eval response.d

时间:2010-05-14 21:53:16

标签: jquery ajax

这样做有什么意义:

var resultsArray = (typeof response.d) == 'string' 
    ? eval('(' + response.d + ')') : response.d;

在$。(ajax)调用的onSuccess()回调中?

1 个答案:

答案 0 :(得分:0)

var resultsArray =                  /* assign a value to resultsArray...        */
  (typeof response.d) == 'string' ? /* ...if the type of response.d is string   */
  eval('(' + response.d + ')')    : /* ...then evaluate it as if it was JS code */
  response.d;                       /* ...else just assign it unaltered         */