1
I created a method that calls data from a database in C#. How can I call this method in Javascript ?
Follows code
[WebMethod]
public copa recuperaDados(int cAno)
{
var con = ConfigurationManager.ConnectionStrings["Data Source=(localdb)/MSSQLLocalDB;Initial Catalog=C:/USERS/BERNARDO/DOCUMENTS/COPA.MDF;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"].ToString();
copa selecionada = new copa();
using(SqlConnection myCon = new SqlConnection(con))
{
string q = "Select * from copa where ano = @ano";
SqlCommand cmd = new SqlCommand(q, myCon);
cmd.Parameters.AddWithValue("@ano", cAno);
using(SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
selecionada.sede = reader["sede"].ToString();
selecionada.campeao = reader["campeao"].ToString();
selecionada.vice = reader["vice"].ToString();
}
myCon.Close();
}
return selecionada;
}
}
javascript
<script type="text/javascript">
$("#CopaList").change(function () {
$("#msg").text("A copa de " + $("#CopaList option:selected").text() + " teve como país(es) sede(s) : " +
+ "O Campeão foi " + + "O Vice Campeão foi " +
)
})
C# does not run on the server and Javascript on the client? I don’t understand how you intend to do this.
– Sam