1

Tengo una consulta y es la siguiente:

Estoy tratando de llenar un etiqueta select desde un archivo json al ejecutar el ajax me sale el siguiente error method not allowed error 405 esta llamando un json local.

Y no encuentro la forma de obtener los datos de mi json.

Método

function get_countries_list() {
    var d1 = $.Deferred();
    $.ajax({
        url: "/app/connect/get_paises/ajax.json",
        type: 'POST',
        dataType: 'json',
        async: true,
        success: function (data) {
            d1.resolve(data);
        },
        error: function (jqXHR, textStatus, errorMessage) {
            d1.reject(new Error(errorMessage));
        }
    });
    return d1.promise();
} 

introducir la descripción de la imagen aquí

Archivo ajax

[{"_id":"57e9e292820cbfd37f0b8cf6","id":34,"nombre":"Alemania","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cd9","id":1,"nombre":"Argentina","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cf2","id":30,"nombre":"Australia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cf3","id":31,"nombre":"Austria","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cdb","id":5,"nombre":"Bolivia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cda","id":2,"nombre":"Brasil","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d00","id":54,"nombre":"Bulgaria","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cff","id":53,"nombre":"B\u00e9lgica","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8ceb","id":23,"nombre":"Canada","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d17","id":1007,"nombre":"Chile","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cfe","id":52,"nombre":"China","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cdc","id":8,"nombre":"Colombia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d0d","id":68,"nombre":"Corea","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8ce2","id":14,"nombre":"Costa Rica","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d01","id":56,"nombre":"Croacia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cf1","id":29,"nombre":"Cuba","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cf5","id":33,"nombre":"Dinamarca","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cdd","id":9,"nombre":"Ecuador","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8ce3","id":15,"nombre":"El Salvador","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d14","id":75,"nombre":"Emiratos Arabes","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d10","id":71,"nombre":"Escocia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d02","id":57,"nombre":"Eslovaquia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d03","id":58,"nombre":"Eslovenia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8ce9","id":21,"nombre":"Espa\u00f1a","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cec","id":24,"nombre":"Estados Unidos","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d04","id":59,"nombre":"Estonia","status":1,"created":1474945682},{"_id":"5a04b9523b96b4e8b32ad72e","id":2000,"nombre":"Filipinas","status":1,"created":1510244446},{"_id":"57e9e292820cbfd37f0b8d05","id":60,"nombre":"Finlandia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8ced","id":25,"nombre":"Francia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cf7","id":35,"nombre":"Grecia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8ce4","id":16,"nombre":"Guatemala","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d18","id":370,"nombre":"Haiti","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cfa","id":38,"nombre":"Holanda","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8ce5","id":17,"nombre":"Honduras","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d06","id":61,"nombre":"Hungria","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d07","id":62,"nombre":"India","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cf4","id":32,"nombre":"Inglaterra","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d15","id":1000,"nombre":"Internacional","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d13","id":74,"nombre":"Irak","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d08","id":63,"nombre":"Irlanda","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cfc","id":40,"nombre":"Israel","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cee","id":26,"nombre":"Italia","status":1,"created":1474945682},{"_id":"5ff72a2bf3f4532a60bda49f","id":2003,"nombre":"Jamaica","status":1,"created":1610033041},{"_id":"57e9e292820cbfd37f0b8cfb","id":39,"nombre":"Japon","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d09","id":64,"nombre":"Letonia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d0a","id":65,"nombre":"Lituania","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d19","id":380,"nombre":"Malasia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8ce6","id":18,"nombre":"Mexico","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8ce7","id":19,"nombre":"Nicaragua","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d0b","id":66,"nombre":"Noruega","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d0c","id":67,"nombre":"Nueva Zelanda","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8ce8","id":20,"nombre":"Panama","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cde","id":10,"nombre":"Paraguay","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cdf","id":11,"nombre":"Peru","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cfd","id":50,"nombre":"Polonia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cea","id":22,"nombre":"Portugal","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cef","id":27,"nombre":"Puerto Rico","status":1,"created":1474945682},{"_id":"614209e8b4a58303a051e5b6","id":2005,"nombre":"Reino Unido","status":1,"created":1631717662},{"_id":"57e9e292820cbfd37f0b8d11","id":200,"nombre":"Republica Checa","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cf0","id":28,"nombre":"Republica Dominicana","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d16","id":1001,"nombre":"Rep\u00fablica de Malta","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d0e","id":69,"nombre":"Rumania","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cf9","id":37,"nombre":"Rusia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d0f","id":70,"nombre":"Singapur","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8d12","id":73,"nombre":"Suecia","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8cf8","id":36,"nombre":"Suiza","status":1,"created":1474945682},{"_id":"5b9816882afa097a77240e0b","id":2001,"nombre":"Tailandia","status":1,"created":1536691116},{"_id":"602ed43c649f302e90d1d59d","id":2004,"nombre":"Trinidad y Tobago","status":1,"created":1613681715},{"_id":"5d67c5e72afa09c27f5034cf","id":2002,"nombre":"Ucrania","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8ce0","id":12,"nombre":"Uruguay","status":1,"created":1474945682},{"_id":"57e9e292820cbfd37f0b8ce1","id":13,"nombre":"Venezuela","status":1,"created":1474945682}]
5
  • No sería mejor usar un GET?
    – Alfabravo
    Commented el 1 mar. 2022 a las 21:08
  • Eso sería mejor pero el código que se esta manejando se llena de esa manera
    – Darwin UM
    Commented el 1 mar. 2022 a las 21:22
  • A ver, reformulo. Estás usando type: 'POST', y yo pregunto si no puedes hacer type: 'GET',
    – Alfabravo
    Commented el 1 mar. 2022 a las 21:26
  • ah ok entendí mal, lo probare
    – Darwin UM
    Commented el 1 mar. 2022 a las 21:39
  • 1
    @Alfabravo ese era la solución muchas gracias.
    – Darwin UM
    Commented el 1 mar. 2022 a las 21:41

1 respuesta 1

1

Para obtener datos del servidor debes utilizar una petición GET

$.ajax({
  url: "/app/connect/get_paises/ajax.json",
  dataType: 'json',
  success: function (data) {
            d1.resolve(data);
        },
        error: function (jqXHR, textStatus, errorMessage) {
            d1.reject(new Error(errorMessage));
        }
});
1
  • ese era la solución muchas gracias.
    – Darwin UM
    Commented el 1 mar. 2022 a las 21:42

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.