JQuery - JQUERY + AJAX + ASMX

 
Vista:
sin imagen de perfil

JQUERY + AJAX + ASMX

Publicado por Borja (3 intervenciones) el 02/10/2014 13:07:32
Hola, tengo un servicio web en asmx al que accedo con AJAX, mi pregunta es la siguiente:
¿estaría bien construido el fichero javascript? quiero decir, se puede hacer un $(document).on("pagecreate"...... dentro de una función que se llama en la llamada al AJAX $(document).ready(function(){ ....

Publico el código por si no se me ha entendido.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var xml;
   var json;
   var Control;
   var maquinas;
   var output;
 
   var ns = "http://localhost/2778/";
   var method_name = "OntenerListaAllControlProduccion";
   var soap_action = "http://localhost/2778/WebServiceControlProduccion.asmx?op=OntenerListaAllControlProduccion";
 
   var CType = "application/xml";
   var DType = "xml";
   var web_url="http://localhost:2778/WebServiceControlProduccion.asmx/ObtenerListaAllControlProduccion";
 
    $(document).ready(function(){
        $.ajax({
            type: "POST",
            url: web_url,
            contentType: CType,
            dataType: DType,
            data:"{}",
            crossDomain: true,
            success: ParseandPaint,
//            complete:  ParseandPaint,         
            error:alert("ERROR?")
//                function(xhr, status, error){ console.log(xhr.responseText, status, error);}
           });
    });
 
    //loading XML file and parsing to .main div.
        function ParseandPaint(data) {
            //pasamos el xml a json
            json = $.xml2json(data);
            alert('PARSEO json!!!!!!!!!');
            Control = $.parseJSON(json);
            alert('parseado!!');
            maquinas = Control.json;
            alert(maquinas);
            output = '';
 
            $(document).on("pagecreate", "#machines", function () {
//            $.each(json, function(index, value){
//             output += '<li><a href="#">' +data.name+ '</a></li>';
//            });
//            $('#list').html(output).listview("refresh");
            $.each(maquinas, function (index, maquinas) {
                output += '<li><h3>' + maquinas.id_maquina + '</h3><ul><li>Nombre Maquina: '+ maquinas.nombre_maquina ;
              });
//            $.each(maquinas, function(i,item){
//                $("#list").append('<li><h3>' + maquinas.id_maquina + '</h3><ul><li>Nombre Maquina: '+ maquinas.nombre_maquina );                 
//             })               
//                $('#list').listview('refresh'); 
                $('#list').html(output).listview("refresh");
 
            })
        }
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

JQUERY + AJAX + ASMX

Publicado por Borja (3 intervenciones) el 02/10/2014 13:36:03
[Solved]

NO SE PUEDE HACER.
El codigo descrito anteriormente quedaria algo asi:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var xml;
   var json;
   var Control;
   var maquinas;
   var output;
 
   var ns = "http://localhost/2778/";
   var method_name = "OntenerListaAllControlProduccion";
   var soap_action = "http://localhost/2778/WebServiceControlProduccion.asmx?op=OntenerListaAllControlProduccion";
 
   var CType = "application/xml";
   var DType = "xml";
   var web_url="http://10.223.4.100:8085/WebServiceControlProduccion.asmx/ObtenerListaAllControlProduccion";
 
   $(document).on("pagecreate", "#machines", function () {
        $.ajax({
            type: "POST",
            url: web_url,
            contentType: CType,
            dataType: DType,
            data:"",
            crossDomain: true,
            success: ParseandPaint,
//            complete:  ParseandPaint,         
            error:alert("ERROR")
//                function(xhr, status, error){ console.log(xhr.responseText, status, error);}
           });
    });
 
    //loading XML file and parsing to .main div.
        function ParseandPaint(data) {
            //pasamos el xml a json
            json = $.xml2json(data);
            alert('PARSEO json!!!!!!!!!');
            Control = $.parseJSON(json);
            alert('parseado!!');
            maquinas = Control.json;
            alert(maquinas);
            output = '';
 
 
//            $.each(json, function(index, value){
//             output += '<li><a href="#">' +data.name+ '</a></li>';
//            });
//            $('#list').html(output).listview("refresh");
            $.each(maquinas, function (index, maquinas) {
                output += '<li><h3>' + maquinas.id_maquina + '</h3><ul><li>Nombre Maquina: '+ maquinas.nombre_maquina ;
              });
//            $.each(maquinas, function(i,item){
//                $("#list").append('<li><h3>' + maquinas.id_maquina + '</h3><ul><li>Nombre Maquina: '+ maquinas.nombre_maquina );                 
//             })               
//                $('#list').listview('refresh'); 
                $('#list').html(output).listview("refresh");
        }
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar