0

I am trying to call a simple hellowworld function of ASP .NET WebService using JQuery AJAX call written in separate HTML file i.e. Not aspx file in ASP .NET. Here is code of my AJAX call which works fine in aspx based web client.

$.ajax({
            type: "POST",
            url: "/Test1/RSSReader.asmx/GetRSSReader",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                $("#output").text(msg.d);
            },
            error: function (e) {
                $("#output").html("WebSerivce error " + e.responseText);
            }
        });

I want to call same webservice and same method using .html file but it is returning error. I tried giving server address i.e. localhost but still no response.

Zia ur Rehman
  • 331
  • 1
  • 2
  • 20
  • error means it execute ERROR block of AJAX not success also there is no value in e.responseText. i.e. it just shows "WebSerivce error ". – Zia ur Rehman Apr 19 '15 at 09:35
  • Are you sure , you are returning JSON format data , and make user your webservice works independently via fiddler or postman rest client in chrome or any other tool. – Arindam Nayak Apr 19 '15 at 09:37
  • Is the "separate HTML file" from where the ajax is called hosted in the same application? If not, it might be a "Same origin policy" issue. – shakib Apr 19 '15 at 09:39
  • No it is not hosted in same location but that is the point i want to call webservice remotely – Zia ur Rehman Apr 19 '15 at 09:42
  • You are right when i copy HTML to same application which have webservice it works fine. But i want to call webservice remotely. i.e. separate client and server locations. – Zia ur Rehman Apr 19 '15 at 09:45
  • Then you have to implement CORS: http://www.html5rocks.com/en/tutorials/cors/ and take a look here: http://stackoverflow.com/questions/4536139/how-to-add-custom-header-to-asmx-web-service-call-using-jquery?rq=1 – Legends Apr 19 '15 at 09:47

0 Answers0