Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
How to call GET Api with input param use JQuery and JavaScript in Asp.net view when a special tag load

Hi I want to load count of orders in my view (in a special tag), I wrote a SP in Sql which return count of order according to input type. I design several box in my form to show all types order count. So I give "Id" to my tag and I want when form loads, this tag show the number. I wrote a script at the bottom of my view. View and script and controller :

     <div class="inner">
            <h3 id="Orders1"><sup style="font-size: 20px"></sup></h3>
            <p>New Orders </p>
     </div>

<script>
    $("#Orders1").load(
    function () {
        $.ajax({
            url: '/Report/GetResultTestData',
            data: JSON.stringify({
                id: 1 /// input value 
            }),
            type: 'GET',
            contentType: 'application/json; charset=utf-8'
        }); 
   </script>

And My controller is like bellow :

    [HttpGet]
    public IActionResult GetResultTestData(int id )
    {
        var data = _sv.GetResultTestData(id);

        return new JsonResult(data);
    }

but unfortunately it doesn't show anything would you please guide me!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Update

  <div class="inner">
            <h3 id="Orders1"><sup style="font-size: 20px"></sup></h3>
            <p>New Orders </p>
            <span id="result2"></span>//add the id to put the result id
     </div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>

      $(document).ready(function () {                  
        $.ajax({
            url: '/Report/GetResultTestData',
            data: {id: 1},
            type: 'GET',
            contentType: 'application/json; charset=utf-8',
            success: function (result) {
                    $('#result2').html(result);
                }// add the success to pass the result
        });
      });
   </script>

Controller:

    [HttpGet]
    public IActionResult GetResultTestData(int id )
    {
        return Content(id, "text/plain");
    }

Result:

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda