Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
Ajax 500 error cause investigation method

I want to get the url sent by Ajax in fuctions.php on the site made by Wordpress.   With the current code, the following error is displayed on the console.
I checked it from the network with the verification tool, but the preview is a white background and no response is displayed.
I would like to find out the cause of the error, what should I do?

Error

XMLHttpRequest : 500
textStatus     : error
errorThrown    : undefined

Code
main.js

(function($) {
    var url_category = location.href;
    var ajaxUrl = window.location.protocol + '//' + window.location.host + '/wp-content/themes/example/functions.php';
    $.ajax({
        url: ajaxUrl,
        type: "GET",
        data: { url_category: url_category },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log("Failed!");
            console.log("XMLHttpRequest : " + XMLHttpRequest.status);
            console.log("textStatus     : " + textStatus);
            console.log("errorThrown    : " + errorThrown.message);
        },
        success: function (response) {
            console.log("Success!");
            console.log(url_category);
        }
    });
})(jQuery);

functions.php

add_action('wp_ajax_get_case', 'dk_get_case');
add_action('wp_ajax_nopriv_get_case', 'dk_get_case');
function dk_get_case() {
    $headers['Access-Control-Allow-Origin'] = '*';
    $return = ['status' => false, 'data' => [], 'message' => ''];

    $url = $_POST['url_category'];
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda