0

I am trying to connect W3Schools sample webservice via jQuery Ajax but it's not working for me.

Here is the JS:

function ConnectToWebService() {
    var pdata = "Celsius:123";

    $.ajax({
        type: "POST",
        dataType: "text",
        data:pdata,
        contentType: "application/text; charset=utf-8",
        url: "http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit",
        success: function (msg) {
            $('#divToBeWorkedOn').html(msg.d); 
        },
        error: function (e) {
            alert("could not connect to service");
        }
    });
}
Unihedron
  • 10,251
  • 13
  • 53
  • 66
Addy
  • 2,608
  • 10
  • 52
  • 98

2 Answers2

0

The error on the page says $.mobile is undefined. Include the proper URL to where $.mobile is defined and try again.

Captain Kenpachi
  • 6,435
  • 6
  • 42
  • 64
0

This line doesn't work:

$.mobile.allowCrossDomainPages = false;

If you take it off your javascript will work. Just so you know, I'm getting here that "could not connect to service".

Next time insert some logs or alerts in your code to debug. I just put one before and one after the line that was not working to see if the ajax request was being sent and saw that this line was the problem.

(In chrome ctrl+shift+c opens debug window, open console and you can see js logs (console.log). A lot better than alert for debug)

Ps: For cross domain ajax call use jsonp, as Ehsan Sajjad commented:

Ps2: I never used this, but it might be useful: Cross-origin Ajax

Community
  • 1
  • 1
t.pimentel
  • 1,225
  • 2
  • 16
  • 24