Showing posts with label webservice. Show all posts
Showing posts with label webservice. Show all posts

Tuesday, 7 September 2010

Calling AJAX with JQuery - Accepted parameters

Calling AJAX with JQuery

AJAX permit us to make calls to a webservice from Javascript. Bear in mind that the Javascript code is executed in the client computer.

Let's see how make an AJAX call using JQuery.

In the Head of our HTML code we have to link the JQuery library. (Google offers us without need to download or add to our project)

src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.js"

In the Javascript code:
The code base to make a call is the follow:

//Option 1.

$.ajax({
type: "GET",
url: URL,
success: allOK(msg),
error: ajaxError
}
);
//function that will be executed if the AJAX call is succesfull
function allOK(data){
alert(data);
}
//function that will be exected if the AJAX call fail
funtcion ajaxError(result){
alert("ERROR: " + result.status + ' ' + result.statusText);
}


//Opction 2.

$.ajax({
type: "GET",
url: URL,
success: function(msg) {
alert(msg);
},
error: function(result){
alert("ERROR: " + result.status + ' ' + result.statusText);
}
);

We can use the 2 notation types to treat the result.

1: Trating the result outside of the call using functions.
2: TTreating the result inside of the call.

A table with all parameter accepted for a AJAX call with the according description attached below.









Regards.

Llamada AJAX con JQuery - Parametros posibles

Llamada AJAX con JQuery - Parámetros posibles


AJAX nos permite hacer llamadas a un servicio web desde javascript. Recordad que Javascript se ejecuta en la máquina cliente.

Veamos pues como ejecutar una llamada AJAX usando JQUERY.

En el head del código HTML debemos linkar la librería JQuery(google la ofrece sin necesidad de descargarla y añadirla al proyecto):

src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.js"

En el código JAVASCRIPT:
El código básico para hacer una llamada es el siguiente:


//Opción 1.
$.ajax({
type: "GET",
url: URL,
success: todoBien(msg),
error: ajaxError
}
);
//función que será ejecutada si la llamada AJAX se ha realizado correctamente
function todoBien(data){
alert(data);
}
//función que será ejecutada si la llamada AJAX ha fallado
funtcion ajaxError(result){
alert("ERROR: " + result.status + ' ' + result.statusText);
}

//Opción 2.
$.ajax({
type: "GET",
url: URL,
success: function(msg) {
alert(msg);
},
error: function(result){
alert("ERROR: " + result.status + ' ' + result.statusText);
}
);

Como véis podemos usar los 2 tipos de notaciones para tratar el resultado:

1: tratar el resultado fuera de la llamada mediante funciones.
2: tratar el resultado dentro de la llamada.

A continuación adjunto una tabla con todos los parámetros que acepta AJAX con su descripción correspondiente.










Un saludo.

Monday, 6 September 2010

Error Tomcat " permission denied " calling webservice

Error tomcat permission denied calling webservice

This is a usual error when we work with webServices and Tomcat.
Read all Post before prove the solution.

The solution is:

Go to your Tomcat base directory
Find the file 50local.policy ( usually you can find it in "$TOMCAT_BASE/conf/policy.d/" ) If you haven't this directory structure, I'm sure that you can find the file catalina.policy in directory "$TOMCAT_BASE/conf/". (Both file are OK).

You have to edit one of these. At the final of the file you should type this:

//Grant all permissions to the Your Webservice Name
grant codeBase "file:${catalina.base}/webapps/yourWebserviceName/-" {
permission java.security.AllPermission;
};

Finally save the file and restart the server.

* You must replace the red text with your information.

I hope that this resolve your problem.
Regards.