我有以下代码可以在单独的 functions.js 文件中调用 json Web 服务。
function getMajorGroups(){
var element = $(".item-group-button");
$.ajax({
type:"GET",
url:"localhost:6458/posApplication/getAllMajorGroups",
data:"{}",
contentType:"application/json; charset=utf-8",
dataType:"json",
done:successResult(majorGroups),
fail:errorResult(error)
});
}
function successResult(majorGroups){
var mGroups = response.d;
$("#item-groups").empty();
$.each(majorGroups ,function(){
var h3 = $('h3').append(majorGroups.code);
element.append(h3);
$("#item-groups").prepend(element);
});
}
function errorResult(error){
alert("error");
}
当我运行网页并使用 firebug 跟踪步骤时,我可以看到脚本已执行。但它不会在 ajax 调用中执行成功或失败代码。我在这里做错什么了吗?
下面是服务返回的字符串示例。
{"majorGroups":[{"update":"false","hasMore":"false","status":"A","description":"Beverage","majorGroupId":"48","code" :"Beverage"},{"update":"false","hasMore":"false","status":"A","description":"Laundry","majorGroupId":"51","code" :"洗衣店"},{"update":"false","hasMore":"false","status":"A","description":"Cigarette","majorGroupId":"50","code" :"Cigarette"},{"update":"false","hasMore":"false","status":"A","description":"Food","majorGroupId":"47","code":"Food"},{"update":"false","hasMore":"false","status":"A","description": "健康中心","majorGroupId":"52","code":"健康中心"}],"failure":"false"}