下面是调用 json web 服务的 jquery 代码。
function getMajorGroups(){
var element = $(".item-group-button");
var response = $.ajax({
type:"GET",
url:"http://localhost:6458/posApplication/touch/getAllMajorGroupsForTouch",
dataType: "json",
contentType: "application/json; charset=utf-8",
data:{}
});
response.done(function(data){
alert(data);
});
response.fail(function() {
$("#item-groups").empty();
});
}
我连接到本地主机中的服务,并且 URL 如上所述!当我删除 http:// 时,response.fail 只会运行。当我添加 http:// 成功或失败都不会运行。我写的这个方法是错误的还是有什么遗漏。我在这里调用 JSON Web 服务!
当我在浏览器中尝试时,网络服务返回一个 JSON 字符串!我正在调用 GET 类型的服务方法。
更新 :
这是我在浏览器中直接使用 URL 时的 Json 响应。
{"majorGroups":[{"update":"false","hasMore":"false","status":"A","description":"Beverage","majorGroupId":"48","code":"Beverage"},{"update":"false","hasMore":"false","status":"A","description":"Laundry","majorGroupId":"51","code":"Laundry"},{"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":"Health Center","majorGroupId":"52","code":"Health Center"}],"failure":"false"}