NirNiroN
NirNiroN

Reputation: 15

Access denied when calling web service from javascript

My goal is to call a Web Service using Jquery. i found this example from this site : How to use jQuery to call an ASP.NET web service?

i modified it to my use :

function InfoByDate(aUrl){
    var divToBeWorkedOn = '#AjaxPlaceHolder';
    var webMethod = 'http://MyWebService/Web.asmx/GetInfoByDates'
    var parameters = "{'sUrl':'" + aUrl + "'}"

    $.ajax({
        type: "POST",
        url: webMethod,
        data: parameters,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {    
            $(divToBeWorkedOn).html(msg.d);
        },
        error: function(e){
            $(divToBeWorkedOn).html("Unavailable");              
        }
    });
}

Now i get back a js error access denied! my web service is located in the same domain so cross domain is not relevant. Can someone help me with that issue? Cheers NirNiroN

Upvotes: 0

Views: 4245

Answers (3)

rajasaur
rajasaur

Reputation: 5460

Is the webservice available on the same server? Cross server requests are not allowed with Ajax and your webservice must be in the same domain as your JavaScript code to allow it to work.

Upvotes: 0

Jason Jong
Jason Jong

Reputation: 4330

If you're using JavaScript and your not calling the web-service from your own domain, then it wont be allowed. You can use JSONP for cross domain calls however, so try to use that.

You can read up on it here http://en.wikipedia.org/wiki/JSONP

Upvotes: 1

Ben
Ben

Reputation: 7597

Where are you calling this from? If you're not on the same domain (i.e. "mywebservice"), it won't work as you can't do cross-domain ajax calls like that.

If this is the case, I suggest looking into the various options available to you (CORS on the server, using a reverse proxy on the 'client' machine, or JSONP).

Upvotes: 0

Related Questions