I am trying to call webservice over cross domain using jQuery.
Here is my code to call service
$(document).ready(function () {
$.ajax({
type: 'GET',
async: false,
contentType: "application/json",
url: "http://localhost:52136/Service1.svc/Helloworld?callback=func_callbk",
dataType: "jsonp",
success: function (data) {
alert('sucesss')
alert(data.d);
},
error: function (data) {
alert(data);
}
});
});
func_callback = function (data) {
alert(data.data.people[0].id);
}
I am returning simple string from the service.
public string HelloWorld()
{
return "Hello World";
}
Service is called from, but I am getting error
Uncaught SyntaxError: Unexpected token :
in console window of Chrome.
I am getting this string while calling service from the browse:
{"HelloWorldResult":"Hello World"}
Please let me know where am I going wrong?
Thanks in advance.
Your WCF server should be configured to enable
jsonp
withCrossDomainScriptAccessEnabled
Here is a simple working example
Server:
And this is the javascript code
Now you can test it from your browser
and