4
I created a button that calls the search method Ajax
to consume a Web Service Asxm
.
Because the Ajax
does not consume the Web Service?
<asp:Button ID="btnPesquisar" runat="server"
Text="PesquisarEmpresa" OnClientClick="buscarEmpresa();"/>
The Ajax Jquery function
function buscarEmpresa() {
$.ajax({
type: "POST",
url: "../../webService/Ajax.asmx/GetEmpresa",
data: "{'cnpj':'" + $("#inputCnpjEmpresa").val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data.Cnpj);
},
error: function () {
alert("Erro");
}
});
}
My Asmx.Cs
[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 Ajax : System.Web.Services.WebService {
public Ajax () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public static Empresa GetEmpresa(string cnpj)
{
return EmpresaControler.RetornaEmpresa(cnpj);
}
}