I'm doing a web service in C #, to consume its data via javascript (without being an application made in ASP.NET or any .NET technology, I want to use only html and javascript).
My web service has been configured like this:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 PhoneGap : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
And my ajax looks like this:
function GetData() {
$.ajax({
type: 'POST'
//Caminho do WebService + / + nome do metodo
, url: "http://localhost:3458/PhoneGap.asmx/HelloWorld"
, contentType: 'application/json; charset=utf-8'
, dataType: 'json'
//Abaixo adicione as variáveis caso haja alguma.
, data: ''
, success: function (data, status) {
//Caso não ocorra nenhum tipo de erro:
$('.valor').text(data.d);
}
, error: function (xmlHttpRequest, status, err) {
//Caso ocorra algum erro:
$('.valor').html('Ocorreu um erro');
}
});
}
When I try to use the Hello Word of the web service, it is giving an error (Note: I thought I was able to use the local web service for testing but I did not find anything using html and ajax.)
Error:
Failed to load link : Response to preflight request does not pass access control check: No 'Access -Control-Allow-Origin 'header is present on the requested resource. Origin 'null' is therefore not allowed access.