Receive a data from a WebService with JavaScript

0

I want to consult a webservice to which I send a data and I receive a string type list. I tried using the soap.js library but it does not work for me. Is there any way to do it from JavaScript easily without soap.js?

This is the code I have now using jQuery and soap.js that does not work for me:

<script type="text/javascript" src="./files/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="./files/jquery.soap.js"></script>

In the header I also put this code that I think does not run because I can not even get out the alert!

$.soap({
   url: 'http://192.168.0.10:9191/Miservicio.asmx?wsdl',
    method: 'BuscarPoblacion',

    data: {
        codPostal: '08080'
    },

    success: function (soapResponse) {

        // do stuff with soapResponse
        // if you want to have the response as JSON use soapResponse.toJSON();
        // or soapResponse.toString() to get XML string
        // or soapResponse.toXML() to get XML DOM

        alert(soapResponse.toString());
    },
    error: function (SOAPResponse) {
        // show error
    }
 });

I add another solution in JavaScript with JQuery that does not work either but in this case if I get the alert with the message 'error':

var servicioURL = 'http://192.168.0.10:9191/Miservicio.asmx';
var soapMsg = "<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:tem='http://tempuri.org/'><soap:Header/><soap:Body><tem:BuscarPoblacion><!--Optional:--><tem:codPostal>08080</tem:codPostal></tem:BuscarPoblacion></soap:Body></soap:Envelope>";

function OnSuccess(data, status) {
  alert(data.d);
}

function OnError(request, status, error) {
  alert('error');
}

$(document).ready(function() {
  jQuery.support.cors = true;
});

and inside the 'body' tag of the html

<script>
  $.ajax({
    url: servicioURL, 
    type: "POST",
    dataType: "xml", 
    data: soapMsg, 
    processData: false,
    contentType: "text/xml; charset=\"utf-8\"",
    success: OnSuccess, 
    error: OnError });
</script>
    
asked by Popularfan 23.08.2018 в 17:13
source

0 answers