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

172
Vistas
Serving two different functions withing the same js file in an MVC app (no **Jquery** solution please)

I am building an MVC app which will have two different plans for users, one of them with restrictions on some functionalities provided via js. What I need is to serve both plans within the same app but I am a little confused in how would be the best way to implement it. I have planned to include both codes within the same js file and comment both, the restricting function and the un-restricting one and then try to create a function which allows the users to access their plan on a fixed condition. I am wondering if it is even possible to be done and if it is, then someone to bring me a simple example which I could be able to re-factor and reproduce within my app environment.

Sorry if I do not provide any code but it would be very complicated to display here the code of my app. I think I would be done with just a simple example like this:

user A is restricted and user B is unrestricted. The main.js file will allow the users to add text lines to the index.html file. The restriction would be to limit the amount of lines that could be added by the user A, let's say to 5 lines, while the user B would be able to add as many lines as he wants. To do that, as I imagined and said before, both, the addLine function and the restrictedAddLine function would be commented. Then, if user A access the app the main.js file will be served with the restrictedAddLine function uncommented and the addLine function still commented, and viceversa if it is the user B the one who access the app.

If someone is able to bring such an example, or any link to a similar question already answered (which I could not be able to fine out there) it will be highly appreciated.

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

0

Let's say you were doing this on a PHP page:

<?php
// this is a string containing the plan of current logged user
$user_plan=$database->getCurrentUser()->plan;
?>
<html>
<head>

<script text/javascript>
// set a global js variable with the plan
var userPlan='<?php echo $user_plan; ?>';
</script>
</head>
<body>


<input type="button" value="Add line" onclick="add_line()" />

<script text/javascript>
function add_line() {
  if (userPlan=='basic') {
    alert('You can only add one line');
    return;
  } else {
    // add as many lines
  }
}
</script>

</body>
</html>

So the whole point is, to access your user information, make the plan available somewhere in the HTML. Then read the plan from javascript and behave differently depending on it. Also, no need to maintain multiple functions, just use the same and put the condition of the plan inside.

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