0

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

2
  • 1
    Is the webservice located on a different domain than the webpage calling it? If so you are hitting the SOP(same origin policy) problem. Commented Jul 13, 2011 at 5:57
  • give a little more info. is the call to the server made ? can you inspect it with firebug ? is the server giving a response code or something or nothing is executed and you just get a js error like "access denided" with no error code or line info or anything else ? Commented Jul 14, 2011 at 9:14

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

my web service is in the same domain but i always get Access deined
0

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).

2 Comments

Agian my webservice is on the same domain..is it a permission issue?
Sounds like it, yes. Can you call the web service from other clients? I would test it with SoapUI if you haven't already.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.