Showing posts with label jquery. Show all posts
Showing posts with label jquery. 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.

Thursday, 2 September 2010

Error call AJAX JQuery


Error call AJAX with JQuery

I’m sure that you have ever had this problem.

" Access to restricted URI denied ” code: “ 1012 "

Or the AJAX request with JQuery is correct but it seems that don’t run?

Well, is very important to ensure that the call is being made to a service within the same domain as the AJAX service.

I always do the following: I create a web Service likes a Proxy. This will make the intermediary between the AJAX page and the world.

That is, our AJAX page always connect with our Proxy web Service, and this will implement the necessary calls to Internet.


Once done, our AJAX web and our Proxy web Service always will be together anywhere where we deploy them.

I personally, to create the Proxy web Service, use Java, creating a REST service with the Jersey library help. (this library is used to server and client). https://jersey.dev.java.net/

Later I will post a small tutorial on how to create a web Service REST in JAVA and how call to another web Service from JAVA.

Llamar AJAX xon JQuery: http://no-suelo.blogspot.com/2010/09/llamada-ajax-con-jquery-parametros.html


Regards.

Error llamada Ajax Jquery

Error llamada AJAX con JQuery

Seguro que habéis tenido este problema alguna vez...

" Access to restricted URI denied ” code: “ 1012 "

¿O simplemente la petición AJAX con JQuery és correcta pero parece que no hace nada?

Bueno, es muy importante asegurarse que la llamada se esté haciendo a un servicio dentro del mismo dominio que la del servicio AJAX.

En mi caso siempre hago lo siguiente: Creo un web Service que haga de Proxy entre nuestra página AJAX y el mundo...

És decir, nuestra página AJAX se cone
cta siempre contra nuestro web Service Proxy, y éste a su vez implementará las llamadas necesarias al exterior.

Una vez hecho esto, nuestra web AJAX y nuestro web Service Proxy siempre irán juntitos allí donde los despleguemos.

Yo personalmente para crear el web Service Proxy uso Java, creando un REST con la ayuda de la librería Jersey. (Nos sirve para hacer de servidor y de cliente)
https://jersey.dev.java.net/

Más adelante publicaré un pequeño tutorial de cómo crear un web Service JAVA y de cómo hacer llamadas a otro web Service desde JAVA.

http://no-suelo.blogspot.com/2010/09/llamada-ajax-con-jquery-parametros.html

Saludos.