Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all!

I have a ajax function that send values to atualizaBD.aspx page.
But the values of "data: $("form").serialize()" wehen read by processaFormulario() function are null.
I displayed the $("form").serialize() value and they are ok!
Is Where the error?
Thanks!
Fábio
Brazil


default.aspx file:

"Salvar BD": function() {
$.ajax({
   type: "GET",
   url: "../atualizaBD.aspx",
   data: $("form").serialize(), 
   cache: false,
   error: function(msg) { alert("Erro: " + msg); },
   success: function(msg) {
       alert("Ok!");
       allFields.val("");
   }
});


atualizaBD.aspx file:

VB
Imports MySql.Data.MySqlClient
Imports System.Data
Imports System.IO
Imports System.Web
Partial Public Class _Default
    Inherits System.Web.UI.Page
    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        processaFormulario()
    End Sub
    Private Sub processaFormulario()
        Dim db As New DBConnection, dr As MySqlDataReader
        Dim nome, email, senha, sql As String
        nome = Request.QueryString("name")
        email = Request.QueryString("email")
        senha = Request.QueryString("password")
        sql = "insert into teste (name, email, password) values ('" + nome + "','" + email + "','" + senha + "')"
        db.abreBD()
        db.executaComando(sql)
        db.FechaDB()
    End Sub
End Class
Posted
Updated 24-Feb-13 15:59pm
v2

Look at below..
You can also acheive the same through below code..
JavaScript
"Salvar BD": function() {
$.ajax({
   type: "GET",
   //url: "../atualizaBD.aspx",
   //data: $("form").serialize(),
    url: "mainhomesearch.asmx/businesslisting",
   data: "{'keywords':'" + request.term + "','name':'Vinod','Email':'Vinodkumarnie@gmail.com','password':'******'}",
   cache: false,
   error: function(msg) { alert("Erro: " + msg); },
   success: function(msg) {
       alert("Ok!");
       allFields.val("");
   }
});


code below..
mainhomesearch.vb
C#
Public Function businesslisting(ByVal keywords As String, ByVal name As String, ByVal Email As String,ByVal Password As String ) As IList(Of String)

//your code here..

End Function

This is one way of passing more than one values and retrieve the same..
 
Share this answer
 
Use
C#
<webmethod> _
before writing function in codebehind.

since you are using
VB Use
VB
<webmethod> _

if c#
C#
[WebMethod]

Because json does not respond to normal function.

and change the url with calling the method name

url: "../atualizaBD.aspx/your function name",
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900