0

I've got 2 servers with different versions of .NET installed. Server 1 has .NET 1.1 and Server 2 has .NET 3.5.

I have a webservice on the .NET 3.5 server, where the following works fine:

function selectedDateTime(strDate, strHours, strMinutes) {

    $.ajax({
        url: 'webservice.asmx/GetCount',
        type: 'POST',
        data: '{strMeetingDate: "' + strDate + ' ' + strHours + ':' + strMinutes + ':00"}',
        contentType: 'application/json; charset=utf-8',
        dataType: 'jsonp',
        success: function(department) {
            console.log("success: " + department.d); 
        },
        error: function(xhr, status, error) {
            console.log("status message: " + status);
            console.log("error message: " + error);
            console.log("xhr message: " + xhr.responseText);

        }
    });

}

$("#btnTest").click(function(event) {
    selectedDateTime("01/07/2013", "13", "00");
});

I want to use the same script on the older .NET 1.1 server too, but can't move the webservice to the old server because it's written using .NET 3.5, so when I tried and it just gave lots of error messages.

So I thought I should just move the html/javascript above to the old server and tell it to point to the webservice on the new server:

I did, and changed the script above a little to point to the new server:

url: 'http://server2/webservice.asmx/GetCount',

It gave the following message:

http://server2/webservice.asmx/GetDayCount 401 (Unauthorized) 
http://server2/webservice.asmx/GetDayCount Origin http://server1 is not allowed by Access-Control-Allow-Origin. 
XMLHttpRequest cannot load http://server2/webservice.asmx/GetDayCount. Origin http://intranet is not allowed by Access-Control-Allow-Origin. 

So I changed the script above a little again, by changing the json bit to jsonp, as I think jsonp allows crossdomain?

dataType: 'jsonp',

But that didn't solve the problem either, I am now getting:

GET http://server2/webservice.asmx/GetCount?callback=jQuery…2680346152&{strMeetingDate:%20%2201/07/2013%2013:00:00%22}&_=1372680346153 500 (Internal Server Error) 

Anyone know why this is not working, as the webservice and script clearly worked on the new server when both files were together on the same server.

oshirowanen
  • 15,297
  • 82
  • 198
  • 350

1 Answers1

1

Look at this topic.

It is not possible to do an asynchronous POST to a service on another domain, due to the (quite sensible) limitation of the same origin policy. JSON-P only works because you're allowed to insert <script> tags into the DOM, and they can point anywhere.

About how jsonp works

Community
  • 1
  • 1
YD1m
  • 5,845
  • 2
  • 19
  • 23