0

I am trying to retrieve a list of values from a Data Virtualization view using webservices in JQuery. This is what I have upto now and I am getting error from alert(xhr.error). Can any of you help me with any obvious things that I may be overlooking? Much appreciated

 <script src="/jquery-1.11.1.js"></script>
 <script src="/jquery.SPServices-2014.02.min.js"></script>
 <script type="text/javascript" language="javascript">

 $(document).ready(function() {
 $.ajax({
     type: "POST",
     url: "http://xxx/soap11/ValidateSourceCode?wsdl",
 username: "xyz", 
     password: "xyz",
     dataType: "xml",
     data: {},
     processData: false,
     contentType:"text/xml; charset=\"utf-8\"",
     success: function (msg) {
          alert($(msg).text());
          //console.log($(msg).text());
     },
     error: function(xhr, status, error){
              alert(xhr.status);
              alert(xhr.error);

      }
    }); });


  </script>
SharePointDummy
  • 347
  • 1
  • 6
  • 22
  • Seems like `xhr.error` is an `function`. Try to replace it with `xhr.error()` – Red Apr 20 '17 at 08:07
  • Or perhaps alert the error argument instead: `alert(error)` Similarly in the success handler `alert(msg)` instead of `$(msg).text()`. – Knut Forkalsrud Apr 26 '17 at 04:05

3 Answers3

0

Take a look in your network tab in the debugger. You're probably getting a 400 error due to the Same-origin Policy. It basically means you can't make ajax request to a different server than what you have you application hosted on.

https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

NovaPenguin
  • 463
  • 3
  • 8
0

if you are just getting the data from the service method, you can do "GET"

$.ajax({
    type: "GET",
    url: "http://xxx/soap11/ValidateSourceCode?wsdl",
    data: {},
    contentType:"text/xml; charset=\"utf-8\"",
    success: jqSuccess,
    error: jqError
});

or you can try using jquery.soap https://github.com/doedje/jquery.soap/blob/master/README.md

Jeric Cruz
  • 1,899
  • 1
  • 14
  • 29
0

You are getting a wsdl (=soap webservice) in jQuery? You have to use a SoapClient, for example php Soapclient.

And call again your ajax :

$.ajax({
    type: "GET",
    url: "/api/yourLocalSoapClient.php",
    data: {query:'testApi'},
    contentType:"text/xml; charset=\"utf-8\"",
    success: jqSuccess,
    error: jqError
});

Put username/password inside your php Script, and use SoapClient:

http://php.net/manual/fr/class.soapclient.php

You can try a jQuery soapclient: https://github.com/doedje/jquery.soap

But if it's a public application this is forbidden, it will expose your user/password for the webservice, use php, and return your own json.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
neoteknic
  • 1,930
  • 16
  • 32