Pedrosa 30 de mar. de 2009
Como esta o código?
Use alguma lib js que já foi testada em todos os browser por exemplo: Prototype ou JQuery para trabalhar com Ajax.
TFAGUNDES6 31 de mar. de 2009
nesse exemplo eu uso jquery para dar um post no serv. Ai eu estou usando struts mais tu pode passar
qq servlet (ação mapeada) para ele.
JQuery
function verificaRespsota (){
var id = document . getElementById ( 'id' ) . value ;
var ordem = document . getElementById ( 'ordem' ) . value ;
$. post ( "testeAction.do?" , /** aqui é o seguinte : passa o . do o dispatch e os parametros **/
{ dispatch : "verificaOrdem" , id : id , ordem : ordem },
function ( data ){
if ( data == 'true' ){
alert ( 'lala' );
}
}
);
}
Tu ta usando alguma receitinha de bolo para ajax com js ??
Abraços…
Pedrosa 31 de mar. de 2009
Eu uso o Prototype com JSON:
Ex pegando dados em JSON:
function ajaxRequest () {
var url = 'user.list.ajax.logic' ;
var pars = '' ;
// create the ajax request
var myAjax = new Ajax . Request (
url ,
{
method : 'get' ,
parameters : pars ,
onComplete : showResponse
}
);
// outras coisas : )
}
function showResponse ( data ) {
// get the jsonObject
var jsonObject = eval ( '(' + data . responseText + ')' );
// get the user array from the json object
var users = jsonObject . users ;
// update html
var html = "" ;
for ( i = 0 ; i < users . length ; i ++ ) {
html += users [ i ] . name + " - " + formatDate ( new Date ( users [ i ] . birthday ), "dd/MM/yyyy HH:mm" ) + "<br/>" ;
}
var div = document . getElementById ( "ajaxResultDiv" );
div . innerHTML = html ;
}
Site do Prototype:
http://www.prototypejs.org/learn/introduction-to-ajax