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

364
Vistas
How to change $(document).ready (function) to onload special tag in order to pass variable to js function

Each of them supposed to show a value from database when the page loads. So I wrote three $(document).ready(function) with three input for GET controller value. I know they run parallel maybe it is good but I want to see if I wrote only one function (design it Linear) with an input value to pass to GET method, I get higher performance or not.

I change the code bellow :

$(document).ready(function () {
    $.ajax({
        url: '/Home/GetData',
        data: { id: 1 },
        type: 'GET',
        contentType: 'application/json; charset=utf-8',
        success: function (result) {
            $('#result1').html(result);
        }
    });
});

to

function bringData(statusId) {
    $.ajax({
        url: '/Home/GetData',
        data: { id: statusId },
        type: 'GET',
        contentType: 'application/json; charset=utf-8',
        success: function (result) {
            $('#result1').html(result);
        }
    });
};  

and in my view I use onload="bringData(0)" like bellow :

      <div class="inner">
            <h3 ><span id="result1"  onload="bringData(0)"></span><sup 
            style="font-size: 20px"></sup></h3>
            <p>Commited Orders</p>
        </div>

but when I run the code it doesn't show the value?

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

0

onload is not a global attribute you can't just stick it on any element and expect it to work.

What you should have done was call bringData from the ready function:

$(document).ready(function () {
    bringData(0);
});

function bringData(statusId) {
    $.ajax({
        url: '/Home/GetData',
        data: { id: statusId },
        type: 'GET',
        contentType: 'application/json; charset=utf-8',
        success: function (result) {
            $('#result1').html(result);
        }
    });
};

If you insist on using an onload attribute, then it should be on the <body> tag

<body onload="bringData(0)">
    ...
</body>
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