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

116
Vistas
Get Ajax / jQuery variables from external text file

I hope someone can help me with this:

I'm building a website with a product comparisontable (with checkbox filters) and I'm using a Javascript I found on the internet. I have some knowledge of JavaScript, but Ajax en jQuery are new for me :-).

The code that's working:

$(document).ready(function () {

    filter_data();

    function filter_data() {

        $('.filter_data').html('<div id="loading" style="" ></div>');
        
        var action = 'fetch_data';
        var walk = get_filter('walk');
        var bike = get_filter('bike'); 
        var swim = get_filter('swim'); 
        var multi = get_filter('multi'); 
        
        $.ajax({
            url: "functions/fetch_data.php",
            method: "POST",
            data: {
                action: action,
                walk: walk,
                bike: bike,
                swim: swim,
                multi: multi
                            },
            success: function (data) {
                $('.filter_data').html(data);
            }
        });
    }

    function get_filter(class_name) {
        var filter = [];
        $('.' + class_name + ':checked').each(function () {
            filter.push($(this).val());
        });
        return filter;
    }


    $('.common_selector').click(function () {
        filter_data();
    });

});

This code is working, but ... the variables inside this function, need to be generated from an external text file. Because the variables need to be edited easily and very frequent. And there are a lot more variables than you see in this code.

And this is what my (shortened) textfile looks like:

1,brand,Brand
2,walk,Walk
2,bike,Bike
2,swim,Swim
2,multi,Multi

The numbers indicate whether the field should be used in the filter or not. Lines with number 2 are the variables, and need to be 'pasted' in the code as variables and datafields.

Is it possible to get the fields/variables from the textfile within Javascript Ajax / jQuery? So with an extra function?

I hope someone can help me with this, I've been working on it for many hours but I can't get it to work properly.

Thanks!!

about 4 years ago · Juan Pablo Isaza
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