I created a Java web service in Netbeans 7.1.2 and managed to create a Java client also through netbeans to test it, and it worked. I then tried to create a jQuery client but failed.
The jQuery client code is:
$.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);
}
The function I am trying to call is:
@WebMethod(operationName = "getHello")
public String getHello(@WebParam(name = "val", targetNamespace =
"http://clubinservice/") String val) {
return "Hello " + val + "!";
}
When using jQuery to consume the Java web service, I receive this error and have no clue what it means:
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};function (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.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;error;
Feel free to try and use the function on the web service if it will help. Any help would be great!
Thanks
EDIT
After realising that i should be using JSON.stringify and thus:
function OnSuccessCall(response) {
alert(JSON.stringify(response));
}
function OnErrorCall(response) {
alert(JSON.stringify(response));
}
I received a different error message:
{"readyState":0,"responseText":"","status":0,"statusText":"error"}
After looking here and here I tried
$.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));});
which also returned the error message:
{"readyState":0,"responseText":"","status":0,"statusText":"error"}