【发布时间】:2012-08-07 15:38:28
【问题描述】:
我在 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};函数 (){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};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,"拒绝"],进度:[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]))}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
如果有帮助,请随时尝试使用网络服务上的功能。任何帮助都会很棒!
谢谢
编辑
在意识到我应该使用 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"}
【问题讨论】:
-
警报响应直接在 OnErrorCall 函数上。并发布消息。
-
谢谢。直接警告“响应”会导致 [object object]。我使用 JSON.stringify 来解决这个问题。上面发布的错误。
标签: java jquery web-services