Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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>
Posted
Updated 8-Oct-15 22:26pm
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900