我在 Netbeans 7.1.2 中创建了一个 Java Web 服务,并设法通过 netbeans 创建了一个 Java 客户端来测试它,并且它工作正常。然后我尝试创建一个 jQuery 客户端但失败了。
jQuery客户端代码是:
$.ajax({
type: "POST",
url: "http://luke-test.j.layershift.co.uk/ClubInService/getHello",
data: "{val:luke}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccessCall,
error: OnErrorCall
});
function OnSuccessCall(response) {
$tmp = "";
$.each(response, function(index, element) {
$tmp += element + ";";
});
alert($tmp);
}
function OnErrorCall(response) {
$tmp = "";
$.each(response, function(index, element) {
$tmp += element + ";";
});
alert($tmp);
}
我试图调用的函数是:
@WebMethod(operationName = "getHello")
public String getHello(@WebParam(name = "val", targetNamespace =
"http://clubinservice/") String val) {
return "Hello " + val + "!";
}
使用 jQuery 使用 Java Web 服务时,我收到此错误并且不知道这意味着什么:
0;function (a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this}; function (){return s===2?n:null};function (a){var c;if(s===2){if(!o){o={};while(c=bG. exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c};函数(a){ s||(d.mimeType=a);return this};function (a){a=a||"abort",p&&p.abort(a),w(0,a);return this};function () {if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1])) }return this};function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0 ],e[1]))}return this};function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k =a,o(e[0],e[1]))}return this};function (){return e};function (){return!!i};function (){return!!i};function (a,b,c){i.done(a).fail(b).progress(c);return this};function (){i.done.apply(i,arguments).fail.apply(i,arguments);return this};function (a,b,c){return f.Deferred(function(d){f.each ({done:[a,"resolve"],fail:[b,"reject"],progress:[c,"notify"]},function(a,b){var c=b[0],e= b[1],g;f.isFunction(c)?ia:ia})}).promise()};function (a){if(a==null)a=h;else for(var b in h )a[b]=h[b];return a};function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&& (k=a,o(e[0],e[1]))}return this};function (){if(c){var a=c.length;n(arguments),j?l=c.长度:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this};function (){if(c){var a=c.length;n(arguments ),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}返回这个};函数(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];否则 b=a[v.status],v.then(b,b)}返回这个};;0;错误;apply(i,arguments);return this};function (a,b,c){return f.Deferred(function(d){f.each({done:[a,"resolve"],fail:[b, "reject"],progress:[c,"notify"]},function(a,b){var c=b[0],e=b[1],g;f.isFunction(c)?ia:ia })}).promise()};function (a){if(a==null)a=h;else for(var b in h)a[b]=h[b];return a};function ( ){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]) )}return this};function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[ 0],e[1]))}返回这个};function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&( k=a,o(e[0],e[1]))}return this};function (a){if(a){var b;if(s<2)for(b in a)j[b ]=[j[b],a[b]];否则 b=a[v.status],v.then(b,b)}return this};;0;error;apply(i,arguments);return this};function (a,b,c){return f.Deferred(function(d){f.each({done:[a,"resolve"],fail:[b, "reject"],progress:[c,"notify"]},function(a,b){var c=b[0],e=b[1],g;f.isFunction(c)?ia:ia })}).promise()};function (a){if(a==null)a=h;else for(var b in h)a[b]=h[b];return a};function ( ){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]) )}return this};function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[ 0],e[1]))}返回这个};function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&( k=a,o(e[0],e[1]))}return this};function (a){if(a){var b;if(s<2)for(b in a)j[b ]=[j[b],a[b]];否则 b=a[v.status],v.then(b,b)}return this};;0;error;延迟(函数(d){f.each({完成:[a,“解决”],失败:[b,“拒绝”],进度:[c,“通知”]},函数(a,b){ var c=b[0],e=b[1],g;f.isFunction(c)?ia:ia})}).promise()};function (a){if(a==null)a =h;else for(var b in h)a[b]=h[b];return a};function (){if(c){var a=c.length;n(arguments),j?l= c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}返回这个};function (){if(c){var a=c.length;n (参数),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this};function (){if(c){ var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this};函数(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status] ,v.then(b,b)}return this};;0;error;延迟(函数(d){f.each({完成:[a,“解决”],失败:[b,“拒绝”],进度:[c,“通知”]},函数(a,b){ var c=b[0],e=b[1],g;f.isFunction(c)?ia:ia})}).promise()};function (a){if(a==null)a =h;else for(var b in h)a[b]=h[b];return a};function (){if(c){var a=c.length;n(arguments),j?l= c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}返回这个};function (){if(c){var a=c.length;n (参数),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this};function (){if(c){ var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this};函数(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status] ,v.then(b,b)}return this};;0;error;e=b[1],g;f.isFunction(c)?ia:ia})}).promise()};function (a){if(a==null)a=h;else for(var b in h)a[b]=h[b];return a};function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!== !0&&(k=a,o(e[0],e[1]))}return this};function (){if(c){var a=c.length;n(arguments),j?l= c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}返回这个};function (){if(c){var a=c.length;n (参数),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}返回这个};函数(a){if(a) {var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b )}返回这个};;0;错误;e=b[1],g;f.isFunction(c)?ia:ia})}).promise()};function (a){if(a==null)a=h;else for(var b in h)a[b]=h[b];return a};function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!== !0&&(k=a,o(e[0],e[1]))}return this};function (){if(c){var a=c.length;n(arguments),j?l= c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}返回这个};function (){if(c){var a=c.length;n (参数),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}返回这个};函数(a){if(a) {var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b )}返回这个};;0;错误;j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}返回这个};function (){if(c){var a=c .length;n(参数),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}返回这个};函数(a){ if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then (b,b)}return this};;0;error;j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}返回这个};function (){if(c){var a=c .length;n(参数),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}返回这个};函数(a){ if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then (b,b)}return this};;0;error;
如果有帮助,请随意尝试并使用 Web 服务上的功能。任何帮助都会很棒!
谢谢
编辑
在意识到我应该使用 JSON.stringify 之后:
function OnSuccessCall(response) {
alert(JSON.stringify(response));
}
function OnErrorCall(response) {
alert(JSON.stringify(response));
}
我收到了不同的错误消息:
{"readyState":0,"responseText":"","status":0,"statusText":"error"}
$.post("http://luke-test.j.layershift.co.uk/ClubInService/getHello",
{val: "John"},
function(data){
alert(JSON.stringify(data));
}, "json")
.error(function(data){alert(JSON.stringify(data));});
它还返回了错误消息:
{"readyState":0,"responseText":"","status":0,"statusText":"error"}