从响应中获取值时出现ajax问题

时间:2011-02-18 05:29:10

标签: ajax json grails prototypejs

我的控制器getJson中有一个功能。它工作正常;我得到了一个AJAX响应。

代码

def getJson = {

// BillingController obj= new BillingController()
//  ResultSet results = obj.showBillingPeriod()
def c= BillingPeriod.createCriteria()

def results = c{

         and{
              max("billingStartDate")
              max("billingEndDate")
         }
   maxResults(1)
      order("billingStartDate", "desc")
 }

   render results as JSON
}

AJAX

  var baseUrl = "${createLink(controller:'billingPeriod', action:'getJson')}"

   new Ajax.Request(baseUrl, {
            method: 'get',
            asynchronous: true,

            onSuccess: function(req) {update(req)}
    });

[{"class":"com.indivar.cmcs.master.BillingPeriod","id":53,"billingEndDate":"25-02-2011","billingStartDate":"28-02-2011","dateCreated":"17-02-2011","enteredBy":0,"lastUpdated":"17-02-2011"}]

现在,我想从billingEndDate获取billingStartDateresponse的值,并将其显示在警告中。我尝试了一切,但它没有奏效。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

onSuccess: function(req) {
   alert(req.responseJSON["billingStartDate"]);
   alert(req.responseJSON["billingEndDate"]);
}