This is the response to my ajax call. I want to handle each array element to update the title of a corresponding button on my page that has the value of the Letter element. I need to replace the alert(response); with a loop over the json array.
{“COLUMNS”:[“PAGESNUM”,”LETTER”],”DATA”:[[“372″,”A”],[“922″,”B”],[“779″,”C”],[“378″,”D”],[“132″,”E”],[“353″,”F”],[“551″,”G”],[“591″,”H”],[“6″,”I”],[“340″,”J”],[“261″,”K”],[“314″,”l”],[“837″,”M”],[“88″,”N”],[“120″,”O”],[“303″,”P”],[“14″,”Q”],[“355″,”R”],[“762″,”S”],[“235″,”T”],[“12″,”U”],[“44″,”V”],[“581″,”W”],[“49″,”Y”],[“19″,”Z”]]}
$.ajax({
type: "Get",
url: "cfc/basic.cfc?method=CountUsersByLetter&returnformat=json",
data: "nbw=" + nbw,
datatype: "html",
success: function (response) {
//usercount = parseInt(response.substring(0, 10));
///$(_$this.target).attr('title', usercount);
alert(response);
},
error: function (xhr, textStatus, errorThrown) {
alert('errorThrown');
}
});
javascript is case sensitive, so you’re going to want to make that parameter
dataTypeand if you’re getting JSON back, then don’t tell jQuery that you’re expecting “html”If you need to do some looping, your arrays are
response.COLUMNSandresponse.DATA(which is an array of arrays).or to loop over the nested array