Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
message shows undefined when ajax post in ASP.net

Hi I'm Fairly new at coding and in asp.net and had an error occurred to me please help me if you can. This is my script when I run the code given below using an onclick function the success message shows as undefined and c# function SaveData which I placed in break point doesn't hit. clearly the post didnt reach the server function.

text1 and text2 are two variables

$.ajax({
    type: "post",
    contentType: "application/json; charset=utf-8",
    url: "Default.aspx/SaveData",
    data: "{dataval: '" + text1 + "', dataval1: '" + text2 + "'}",
    dataType: "json",
    success: function (data) {
        alert(data.d);
    },
});

server side

[WebMethod]
public static string SaveData(string dataval, string dataval1)
{
    string data = String.Format("Your Name is {0} and address is {1}", dataval, dataval1);
    return data;
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I have created this sample and working fine. Please check below answer.

$.ajax({
        type: "GET",
        url: "/Home/SaveData",
        data: { dataval: 'asd', dataval1: 'asd' },
        dataType: "json",
        success: function (data) {
            debugger
            alert(data);
        },
        });
    });

Backend

[HttpGet]
    public ActionResult SaveData(string dataval, string dataval1)
    {
        string data = String.Format("Your Name is {0} and address is {1}", dataval, dataval1);
        return Json(data, JsonRequestBehavior.AllowGet);
    }

I hope this helped you out.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda