Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá Galera,
Alguém tem exemplos práticos de como eu posso utilizar o AJAX com ASP para enviar form de contato e até mesmo fazer inclusão ou remover dados?
Ajax com JQuery ou sem? Qual melhor solução?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Teste ajax jquery tutsmais</title>
<script src="[http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js](http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js)"> </script>
<script>
$(function(){
$('input[type=submit]').click(function(){
$.ajax({
type : 'post',
url : 'teste.php',
data : 'nome='+ $('#campo1').val() +'&sobrenome='+ $('#campo2').val(),
dataType : 'html',
success : function(txt){
$('body p').html(txt);
}
});
});
});
</script>
</head>
<body>
<h2>form via ajax</h2>
Digite seu nome:</label> <input type="text" id="campo1" /><br />
Digite seu sobrenome:</label> <input type="text" id="campo2" /><br />
<input type="submit" /><br />
<p></p>
</body>
</html>Espero ter ajudado =D
Exemplo de ajax no asp:
<script language="javascript">
Function AjaxForm1Function () {
var ajaxForm1 = new createXMLHTTP();
ajaxForm1.open("post", "ajaxPaginaQueIraReceberOsDados.asp", true);
ajaxForm1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxForm1.onreadystatechange=function(){
if (ajaxForm1.readyState==4){
document.all.IdDoElementoQueIráReceberOConteudoDoAjax.innerHTML = ajaxForm1.responseText;
}
}
ajaxForm1.send("opcaoParaEnviar1="+opcao1+"&opcaoParaEnviar2="+opcao2);
}
</script>Irei usar SQL Server como exemplo de select para preenchimento de uma tabela com um radio para chamar uma function na pagina que realizou o ajax...
ajaxPaginaQueIraReceberOsDados.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Response.Charset="utf-8"
dim sql, rs, conn, opcao1, opcao2
opcao1 = request("opcaoParaEnviar1")
opcao2 = request("opcaoParaEnviar2")
set conn = server.CreateObject("adodb.connection")
set rs = server.CreateObject("adodb.recordset")
conn.Open "Provider=SQLOLEDB;Data Source=LOCALDOBANCO;Initial Catalog=NOMEDB;UID=USER;PWD=PASSWORD"
rs.CursorLocation = 3
rs.CursorType = 0
rs.LockType = 1
sql = "select * from TABLE where COLUMN = '" & opcao1 & "' or COLUMN ='" & opcao2 & "' order by COLUMN desc"
set rs = conn.Execute(sql)
%>
<table align="left" valign="top" border="1" cellspacing="2" cellpadding="2" bordercolor="#87CEFA">
<tbody>
<tr>
<th align="Center" style="background:none;border:none" colspan="8"><font style="font-size:85%;">Serviços Encontrados</font></th>
</tr>
<tr>
<th align="Center" style="background:#87CEFA"><font style="font-size:85%;"> </font></th>
<th align="Center" style="background:#87CEFA"><font style="font-size:80%;">iten 1</font></th>
<th align="Center" style="background:#87CEFA"><font style="font-size:80%;">iten 2</font></th>
<th align="Center" style="background:#87CEFA"><font style="font-size:80%;">iten 3</font></th>
<th align="Center" style="background:#87CEFA"><font style="font-size:80%;">iten 4</font></th>
<th align="Center" style="background:#87CEFA"><font style="font-size:80%;">iten 5</font></th>
</tr>
<%
if not rs.eof then
rs.MoveFirst
do while not rs.EOF
%>
<tr>
<td align="Center"><input type="radio" name="cod" value="<% Response.Write(rs(0)) %>" onClick="javascript:UmaFunction(this.value);"></td>
<td align="Center"><font style="font-size:85%;"><% Response.Write(rs(0)) %></font></td>
<td align="Center"><font style="font-size:85%;"><% Response.Write(rs(1)) %></font></td>
<td align="Center"><font style="font-size:85%;"><% Response.Write(rs(2)) %></font></td>
<td align="Center"><font style="font-size:85%;"><% Response.Write(rs(3)) %></font></td>
<td align="Center"><font style="font-size:85%;"><% Response.Write(rs(4)) %></font></td>
</tr>
<%
rs.MoveNext
loop
else
%>
<tr>
<td align="Center" colspan="8"><font color="red"><b>Não há itens disponíveis no momento!</b></font></td>
</tr>
<%
end if
if rs.State = 1 then rs.Close
conn.Close
set conn = nothing
set rs = nothing
%>
</tbody>
</table>Dá uma pesquisada no fórum que postei vários exemplos.
Valeu Galera!
Vai ser muito útil.
Obrigado!
Ola, esse codigo deve funcionar, basta criar um novo arquivo e nele incerir o que quer fazer em php ou qualquer outra linguagem: