0

i want to use c# web service with PHP and jQuery. below code is posting data with $.ajax into php code. but inside i=of url i can't get any data from web service. how can help me for develop this code

$.ajax({
          type: "POST",
          url: "http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit",
          dataType: 'jsonp',
          success: function(data) {alert('ok')},
          error  : function(e) {alert('error')}
        });
DolDurma
  • 15,753
  • 51
  • 198
  • 377

1 Answers1

1

You are violating the same origin policy. You cannot send an AJAX request to a remote domain. If you want to consume an ASMX web service from javascript using AJAX, this service must be located on the same domain as the page containing this script.

You seem to have specified dataType: 'jsonp' in your request but this doesn't make any sense if the remote ASMX service is not configured to support JSONP.

As a possible workaround you could write a new PHP script that will act as a bridge between the local and the remote domain and then send the AJAX request to the PHP script. This script will then call the remote web service by sending an HTTP request and return the result:

$.ajax({
    type: 'POST',
    url: '/CelsiusToFahrenheit.php',
    success: function(data) { alert('ok') },
    error: function(e) { alert('error') }
});

The CelsiusToFahrenheit.php script that you need to write then will delegate the call to the remote domain to invoke the actual ASMX service. There are gazillions of tutorials out there about how to call an ASMX web service with PHP. Here's one: Call asp.net web service from PHP with multiple parameters.

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928