0

I'm trying to use a third-party web service to get data, using ajax. The guys, providing the web service gave me a link and a small description on how to get the data and i feel i'm close, but i can't get it to work. So here's what they gave me:

Production URL: 'http://www.locationbasedtech.net/webservice.asmx' Call: getDeviceData(string username, string password, string activationCode)

The function is supposed to return a JSON response, or some of the following error codes: -1 ; -1001; -2001; -3001;

$.ajax({
    url: '//www.locationbasedtech.net/webservice.asmx/getDeviceData?username=myusername&password=mypassword&activationCode=mycode',
    contentType: "application/x-www-form-urlencoded",
    dataType: "script",
    success: function(data) { 
                console.log(data);//returns 'undefined' ??
    },
    error: function(request,status,errorThrown){
                console.log(request+' '+status+' '+errorThrown);              
    }
}) ;

Now i've been able to make it work only with dataType: 'script'. All others return

No 'Access-Control-Allow-Origin' header is present on the requested resource.

Anyway, the above-mentioned code works in means that i can see the correct (no errors json result) in the console link 'preview' or 'source', but the success function returns 'undefined'. How do i get that response?

Radoslav Trenev
  • 353
  • 1
  • 6
  • 17
  • 2
    If they don't support CORS or offer a JSONP service, you aren't going to be able to query the service directly from JavaScript. – Phil Jun 12 '15 at 00:48
  • 1
    possible duplicate of [Loading cross domain html page with jQuery AJAX](http://stackoverflow.com/questions/15005500/loading-cross-domain-html-page-with-jquery-ajax) – Phil Jun 12 '15 at 00:51
  • 1
    If they do support cross origin via jsonp, try this: https://learn.jquery.com/ajax/working-with-jsonp/ – Brian Jun 12 '15 at 01:11
  • Thank you guys, I'll talk to the support. Do you have ideas how can I make this work even if it's not ajax? Perhaps php? – Radoslav Trenev Jun 12 '15 at 01:51

0 Answers0