0

I have code like that

function loadAjaxData(code) {
$.ajax({
                type : 'POST',
                url : 'loadData.html',
                dataType : 'json',
                data : {
                    "limited_num" : limited_num,
                    "search_bunrui_code" : code,
                    "orderType" : orderType,
                    "search_base_date_from" : search_base_date_from,
                    "search_base_date_to" : search_base_date_to,
                    "compare_date_from" : compare_date_from,
                    "compare_date_to" : compare_date_to
},
success : function(data) {
},
});

As i know data above is to pass param to server. and in the server it return for me an array object of Json The question is how can i get that array in the success Thank for any help

here is the code in the server

 @Result(name="loadData",type="json"),

public ArrayList<OrderDeliverAmoutReturnList> returnList;

@Action(value="loadData", results = {
                @Result(name="loadData", type="json", params ={"includeProperties", "returnList"})
            })
    public String loadData() throws Exception{
        OrderDeliverAmoutSearchTO searchTo=this.setCondition();
        returnList=bunruiSummaryService.getBunruiSyouhinShopDayList(searchTo);
        total=this.caculateTotal();

        return "loadData";
    }
1
  • You can create the data array outside the ajax call. Name it differently. Commented Jun 6, 2013 at 8:46

3 Answers 3

1

if you are sending json data with json type header from server then you can get json object directly in data variable inside success method.

for text/html header of server you can use.

var jsonObject = $.parseJSON(data)

to get json or array in jsonObject .

Sign up to request clarification or add additional context in comments.

4 Comments

when i do that i have an error "Uncaught SyntaxError: Unexpected token < jquery-1.8.3.js:514 jQuery.extend.parseJSON". Sorry i am not good at ajax and json
it means the json or array which is sent from a server can not be parsed. can you provide the response you are sending from server.
I dont know much about actionscripts. but can you please provide response data? you may get it from web console of your browser in network panel.
it return the whole html data. i did not see any json hix :(
0

It's in the data variable in the success callback: function(data) { }

Comments

0

here,'data' is itself the json object. if it is array, you can use it like

success : function(data) {
  for(int i=0;i< data.length;i++){
    alert(data[i]);//use it
  }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.