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

615
Visualizações
In ASP.NET Web Forms, how to call a page method using "get" request

In ASP.NET Web Forms, i am able to call page method using Ajax "post" request. But i am not able to call the page method using "get request".

In this case, is it possible to call page methods using "Get" request.?Could you please provide any suggestion for this? Example Code for Page method:

    [WebMethod]
    public static string GetData()
    {            
        return "test";
    }
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

As @vc mentioned in the comments you'll need to make use of the ScriptMethodAttribute as well as WebMethod because you want your request to be GET and not POST so change your code as follows:

[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public static string GetData()
{
   return "test";
}

And in the markup you can do

function ShowTestMessage() {
     $.ajax({
          type: "GET",
          url: "YourPage.aspx/GetData",
          data: {},
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: OnSuccess,
    failure: function (response) {
        alert(response.d);
    }
});
}
function OnSuccess(response) {
alert(response.d);
}

<input id="ButtonId" type="button" value="Show Message"
onclick = "ShowTestMessage()" />

Don't forget to add the following reference

using System.Web.Script.Services;
using System.Web.Services;
over 4 years ago · Santiago Trujillo Relatório

0

Ajax GET requests to an ASP.NET Page Method?

I guess the link would be useful. It says For security reasons, ASP.Net AJAX page methods only support POST requests.

Tried decorating the method with [ScriptMethod(UseHttpGet = true)] but still the get request is not hit.

Also the msdn doc for [ScriptMethod(UseHttpGet = true)] quotes When this property is set to true, the client proxy code uses HTTP GET to call the Web service. Not sure if it works for a webmethod in web forms.

P.S : Well seems to work with the newer versions of Jquery 2.2.2. Also please be sure that you send data through query strings not using request body as in POST method.

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