L
L
Linkouth2018-09-03 19:01:37
AJAX
Linkouth, 2018-09-03 19:01:37

Ajax request fields not being sent?

I'm trying to send an ajax request:

;(function($, undefined){
            $(document).on('click', 'a.ajax', function () {
                $.ajax({
                    url: '{{ path('infrastructure_shift_ajax') }}',
                    type: "POST",
                    datatype: "json",
                    data: {
                        "some_var": "some_value",
                        "employeeId": this.employeeId,
                        "day": this.day,
                    },
                    async: true,
                    success: function (data) {
                        alert(data + " has been sent");
                    }
                });

                return false;
            })
        })(jQuery);

Twig from which the function is called
{% for employee in employees %}
            <tr>
                <td style="min-width: 10px">{{ employee }}</td>
                {% for day in 1..31 %}
                    <td style="min-width: 10px">
                        <a class="ajax" href="#">{{ employee }}</a>
                    </td>
                {% endfor %}
            </tr>
        {% endfor %}

The request contains only the "some_var" field. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lander, 2018-09-03
@usdglander

Maybe all the same

"employeeId": $(this).employeeId,
                        "day": $(this).day,

It's just logical to assume that the problem is in this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question