Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:
 
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 24-Feb-13 12:03pm
Edited 24-Feb-13 16:59pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Look at below..
You can also acheive the same through below code..
"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
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..
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use
<webmethod> _
before writing function in codebehind.
 
since you are using
VB Use
<webmethod> _

if 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",
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 275
1 OriginalGriff 230
2 BillWoodruff 173
3 CPallini 155
4 Kamal Rocks 144
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 24 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100