hello friends... i am trying from so many days to call a web service from javascript... which is available on another domain... means cross domain web service . and i am failing again and again , can anyone tell me how to do it in productive way.
1: the service is like this ..
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class camp : System.Web.Services.WebService {
public camp () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public string HelloWorld() {
return "Hello World... its cross domain";
}
}
2: and script function is like this ....
<script type="text/javascript">
$(document).ready(function () {
var surl = "http://localhost:1061/camp_web_service/camp.asmx/HelloWorldcallback=hello";
$.ajax({
type: 'GET',
url: surl,
crossDomain: true,
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
success: function (msg) {
$.each(msg, function (name, value) {
alert(value);
});
},
error: function (xhr, status, error) { alert('Servidor de error 404 !!'); },
async: true,
cache: false
});
});
</script>