0

I working on a project where I need to use JSON. I am using Struts2, JSON, jQuery. I am sending httprequest to server like this:-

function getBBSJSONData(ths)
{
   //ths is nothing but this pointer
    var id=ths.id;
    var url = 'bbsJsonAction?actionId='+id;

       var myAjax = new Ajax.Request(
        url, 
        {
                method: 'post', 
                onComplete: fetchBBSSuccessData
        });   
}

Now, I am mapping this request in struts.xml like this

 <action name="bbsJsonAction" class="com.x.x.x.BBS_JSON" method="getBBS_json">
            <result type="json"/>
 </action>

Now in my action class I am setting JSON object like this

public String getBBS_json()
{

    JSONObject jsonObj =null;

        Map map = new HashMap();
        map.put("actionId", actionId);
        map.put("count", count);

        jsonObj = new JSONObject(map);
        System.out.println(jsonObj);    

   return SUCCESS;
}

and finally I am retrieving this JSON result as responseText on client side like this:-

function fetchBBSSuccessData(Request){

var d = Request.responseText.evalJSON();

alert(d);                // this shows [object, object]
alert(d.actionId);      //this shows undefined
alert(d.countd);       //this shows undefined
alert(d.jsonData.count);this also shows undefined

}

Why this showing me undefined, How to get the data from this JSON, please suggest me possible changes.

4

0 回答 0