我在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服务时,我会收到这个错误,不知道它意味着什么:
0;函数(a,b){if(!s){var c=a.toLowerCase();a=mc=mc||a,la=b}返回此};函数(){返回s===2?n:null};函数(a){var s===2?n:null c===b?null:c};函数(a){a=a||"abort",p&&p.abort(a),w(0,a);返回此};函数{if(C){var a=c.length;n(参数),j?l=c.length:e&&e!==!0&(k=a,o(e,e1))}返回此};函数(){if(c){var a=c.length;n(参数),j?l=c.length:e&&e!==0&(k=a,o(e,e1))}返回此};函数{if(C){var a=c.length;n(参数),j?l=c.length:e&&e!==!0&(k=a,o(e,e1))}返回此};函数(){返回e};函数(){返回!!i};函数(){返回!!i};函数(a,b,c){i.done(A).fail(B).progress(C);返回此};函数(){i.done.apply(i,参数).fail.apply(i,参数);返回此};函数(a,b,c){返回f.Deferred(函数(D){f.each({f.each:a,“解决”,失败:B,“拒绝”,进度:C,“通知”}),函数(a,b){var c=b,e=b1,f.each (a){if(a==null)a=h;else for(var B in h)ab=hb;return a};函数{if(C){var a=c.length;N(参数),j?l=c.length:e&&e!==!0&(k=a,o(e,e1))}返回此};函数{if(C){var a=c.length;n(参数),j?l=c.length:e&&e!==!0&(k=a,o(e,e1))}返回此};函数(){if(c){var a=c.length;N(参数),j?l=c.length:e&&e!==!0&(k=a,o(e,e1))}返回此};函数{if(A){var b;if(s<2)for(b in a)jb=[jb,ab];否则b=av.status,v.then(b,b)}返回此};;0;错误;
如果有帮助的话,可以尝试使用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"}发布于 2012-08-10 14:32:51
此外,如果您访问另一个url,而不是为您的内容服务的url,则浏览器上有一个安全性。在本例中,您应该阅读有关jsonp的内容:
http://www.fbloggs.com/2010/07/09/how-to-access-cross-domain-data-with-ajax-using-jsonp-jquery-and-php/
https://stackoverflow.com/questions/11899902
复制相似问题