Reputation: 117
I have a working webservice on site A, I have no problem consuming this service from within site A, now I am trying to consume the same service from site B with no success...
Code follows -
$(function () {
$.getJSON("http://siteA.com/Services/myasmx.asmx/dummy",
{
sID: "tempID"
},
function (data) {
//success call
.
.
return false;
});
});
});
Any idea how can I consume site A webservice from site B ?
Thanks
Upvotes: 0
Views: 56
Reputation: 9167
Use $.ajax with dataType: "jsonp" - this will automatically register your callback function for you and avoid the cross domain issue.
Upvotes: 1
Reputation: 3634
Cross-site HTTP Requests are not allowed by modern browsers as a security measure. The correct way to work around this is to use JSONP callback in the URL.
$.getJSON("http://siteA.com/Services/myasmx.asmx/dummy?jsoncallback=?",
function(data){
// do something here
});
Upvotes: 1
Reputation: 7305
This is because cross-domain policy.
If you can had some headers in the response of the webservice, you can easily bypass that.
see : http://www.w3.org/TR/cors/
Upvotes: 0