Problem with URL invoke it with AJAX

0

Sometimes I can invoke it like this:

$.ajax({
        type: "GET",
        url: "Mantenimiento/Encuesta",
        data: { iIdEncuesta: iIdEncuesta },
        success: function (oDatos) {
            $("#divEncuesta").html(oDatos);
        }
    });

and others like this:

$.ajax({
        type: "GET",
        url: "Encuesta",
        data: { iIdEncuesta: iIdEncuesta },
        success: function (oDatos) {
            $("#divEncuesta").html(oDatos);
        }
    });

I do not know for sure what the problem may be and how I should proceed in this regard.

    
asked by Smc 24.08.2017 в 23:21
source

1 answer

0

The problem is probably due to the URL from where you execute the call ajax . In both cases you use path relativos and this is precisely why it sometimes works with a route and other times with the other.

Solution:

Always make calls ajax indicating path absoluto to endpoint .

Assuming that the path absoluto is /api/Mantenimiento/Encuesta , then the call ajax should do it like this:

$.ajax({
    type: "GET",
    url: "/api/Mantenimiento/Encuesta",
    data: { iIdEncuesta: iIdEncuesta },
    success: function (oDatos) {
        $("#divEncuesta").html(oDatos);
    }
});
    
answered by 24.08.2017 / 23:30
source