我在Netbeans 7.1.2中創建了一個Java Web服務,並且還設法通過NetBeans創建一個Java客戶端來測試它,並且它工作正常。然後我嘗試創建一個jQuery客戶端,但失敗了。使用JQuery來使用Java Webservice:錯誤?
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:nul函數(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}; function(a){s ||(d.mimeType = a); return this };函數(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};函數(){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}; fun ction(){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(函數(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。長度: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(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 ;錯誤;
如果能夠幫助,請隨時嘗試使用Web服務上的功能。任何幫助將是偉大的!
感謝
編輯
意識到我應該使用JSON之後。字符串化並且因此:
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功能直接回應。併發布消息。 – 2012-08-10 10:38:35
謝謝。直接提示[對象對象]中的「響應」結果。我用JSON.stringify來解決這個問題。上面顯示的錯誤。 – Luke 2012-08-10 14:25:36