Hi,
I have a very simple asmx webservice in one Visual Studio project
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloWorld()
{
return "helloworld";
}
}
I am trying to call this web service from another project in Visual Studio using ajax call
$(document).ready(function () {
$.ajax({
url: "http://localhost:17889/Service1.asmx/HelloWorld",
type: "POST",
dataType: "jsonp",
crossDomain:true,
contentType: "application/json;charset=utf-8",
success: function (d) {
alert("success");
alert(d.data);
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
console.log(status);
console.log(error);
}
});
});
my web.config looks like this
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://localhost:17889" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
</customHeaders>
</httpProtocol>
the errors are
Uncaught SyntaxError: Unexpected token <<br mode="hold" />
undefined
parsererror
Error: jQuery19004053758140653372_1453581966937 was not called(…)
what's wrong with my approach? I have gone through a lot of posts, but still struggling to get a proper solution.
Please suggest.