AJAX with WEB SERVICE (ASP.NET)

AJAX with WEB SERVICE (ASP.NET)

MagX8MagX8 Posts: 2Questions: 0Answers: 0
edited March 2015 in Free community support

I'm trying to connect ajax with ASP but i don't have results.

this is my web service:

[WebMethod]
public string getEmpresaTablas()
{
string sResult = "";

        try
        {

            int nDraw = Convert.ToInt32(HttpContext.Current.Request.Params["draw"]);
            List<Empresa> lst = Empresa.getEmpresa();

            ReturnData oResult = new ReturnData();
            oResult.draw = nDraw;
            oResult.recordsTotal = lst.Count;
            oResult.recordsFiltered = lst.Count;

            foreach (Empresa o in lst)
            {
                oResult.data.Add("[");
                oResult.data.Add('"'+o.idEmpresa.ToString()+'"'+",");
                oResult.data.Add('"' + o.razonSocial.ToString() + '"' + ",");
                oResult.data.Add('"' + o.nombre.ToString() + '"' + ",");
                oResult.data.Add('"' + o.email.ToString() + '"' + ",");
                oResult.data.Add('"' + o.fono.ToString() + '"' + ",");
                oResult.data.Add('"' + o.fecha_creacion.ToString() + '"' + ",");
                oResult.data.Add('"' + o.fecha_modificacion.ToString() + '"' + ",");
                oResult.data.Add('"' + o.rut.ToString() + '"' + ",");
                oResult.data.Add('"' + o.fecha_inicio.ToString() + '"' + ",");
                oResult.data.Add('"' + o.fecha_termino.ToString() + '"');
                oResult.data.Add("],");
            }

            sResult = oResult.ToString();

        }
        catch (Exception err)
        {
            string sMsg = err.Message;
            sResult = "";
        }

        return sResult;
    }

This is my ajax

$(document).ready(function () {
$('#tblData').dataTable({
"processing": true,
"ajax": "AdministrarEmpresa.aspx/getEmpresaTablas"
});
});

With "server side" parameter, don't conect to webservice

http://es.zimagez.com/zimage/screenshot2225.php

without "server side parameter" connect to webservice but throws an error (invalid format json)

http://es.zimagez.com/zimage/screenshot1493.php

I did ajax with txt file with json ,with the same format json that throws the method "getEmpresaTablas" perfect work. but connect to webservice throw error.

this is a txt file.
{
"draw": 0,
"recordsTotal": 13,
"recordsFiltered": 13,
"data": [
[
"0",
"DEMO",
"DEMO",
"DEMO",
"",
"28/04/2012 0:42:17",
"17/07/2013 0:00:00",
"",
"01/01/0001 0:00:00",
"01/01/0001 0:00:00"
],
[
"1",
"Edalnet",
"Edalnet",
"contacto@edalcom.cl",
"2222222",
"28/04/2012 0:42:17",
"01/01/0001 0:00:00",
"",
"01/01/0001 0:00:00",
"01/01/0001 0:00:00"
],
[
"3",
"COOPREL",
"COOPREL",
"info@cooprel.cl",
"",
"28/04/2012 0:42:17",
"25/05/2013 0:00:00",
"",
"01/01/0001 0:00:00",
"01/01/0001 0:00:00"
],
[
"4",
"IMG",
"IMG",
"",
"",
"28/04/2012 0:42:17",
"01/01/0001 0:00:00",
"",
"01/01/0001 0:00:00",
"01/01/0001 0:00:00"
],
[
"5",
"CRELL",
"CRELL",
"-",
"-",
"28/04/2012 0:42:17",
"03/07/2013 8:23:00",
"",
"01/01/0001 0:00:00",
"01/01/0001 0:00:00"
],
[
"6",
"COMULSA",
"COMULSA",
"-",
"-",
"28/04/2012 0:42:17",
"01/01/0001 0:00:00",
"",
"01/01/0001 0:00:00",
"01/01/0001 0:00:00"
],
[
"7",
"EEPA",
"Empresa Electrica de Puente Alto",
"",
"",
"28/04/2012 0:42:17",
"24/07/2013 10:55:00",
"",
"01/01/0001 0:00:00",
"01/01/0001 0:00:00"
],
[
"8",
"COPELEC",
"-",
"-",
"-",
"29/07/2013 0:00:00",
"01/01/0001 0:00:00",
"",
"01/01/0001 0:00:00",
"01/01/0001 0:00:00"
],
[
"9",
"CODINER",
"CODINER",
"-",
"-",
"30/07/2013 15:26:00",
"30/07/2013 15:26:00",
"78.397.530-0",
"01/01/0001 0:00:00",
"01/01/0001 0:00:00"
],
[
"10",
"COELCHA",
"COELCHA",
"-",
"-",
"31/07/2013 0:00:00",
"31/07/2013 0:00:00",
"",
"01/01/0001 0:00:00",
"01/01/0001 0:00:00"
],
[
"11",
"CARBOMET",
"CARBOMET",
"-",
"-",
"07/11/2013 18:42:05",
"01/01/0001 0:00:00",
"",
"01/01/0001 0:00:00",
"01/01/0001 0:00:00"
],
[
"12",
"CAMUR",
"CAMUR",
"mtorres@camur.cl",
"673848",
"10/11/2013 21:05:35",
"01/01/0001 0:00:00",
"",
"01/01/0001 0:00:00",
"01/01/0001 0:00:00"
],
[
"13",
"ELIQSA",
"ELIQSA",
"-",
"-",
"18/12/2013 11:56:27",
"01/01/0001 0:00:00",
"",
"01/01/0001 0:00:00",
"01/01/0001 0:00:00"
]
]
}

then my question is, How I can connect ajax with a web service ASP.NET?

I need help please. Sorry for my bad english.

Replies

  • MagX8MagX8 Posts: 2Questions: 0Answers: 0

    Admin or moderator delete discussion, please.

This discussion has been closed.