Support » Plugins » Hacks » Ajax 500 Internal Server Error

  • Hi there,

    I am trying to utilize ajax-functionality for a plugin I am creating, but get a 500 Internal Server Error when trying to do so. Here is what I am doing:

    1. User changes something on plugin-page.
    2. The change is registered through JavaScript (jQuery).
    3. a jQuery.Post call is made to a function named ajax_callback, as seen below.
    4. The call tries to send two variables to the function: ‘caseType’ and ‘data’.
    5. ajax_callback checks whether ‘caseType’ is defined, and if it is proceeds with printing ‘data’.

    However, step 5 fails, and only the backfire of ajax_callback is printed. The jQuery.Post call looks like this:

    $.post(ajaxurl, {
      action: "ajax_callback",
      caseType: "1",
      data: array1
    }, function(data) {
    }, "text");

    And the axax_callback looks like this:

    add_action('wp_ajax_ajax_callback', 'ajax_callback');
    function ajax_callback() {
      if (!$_POST['caseType']) {exit("caseType is not defined");}
      switch ($_POST['caseType']) {
      case "1":
        $data = $_POST['data'];
      case "2":
        $data = $_POST['data'];

    So basically, ‘caseType’ defines what to do, and ‘data’ is passed on. But why am I getting the backfire from saying “caseType is not defined”? As seen by the JavaScript code, case “1” of the ajax_callback should be invoked, and the ‘data’ printed directly.

    Any ideas on what is going wrong?

Viewing 1 replies (of 1 total)
  • Solution: There is actually nothing wrong with the code above. However, admin-ajax.php has no solution for error handling other than directly linked to itself and the request from JavaScript. Meaning: My error came from the callback function in my php, and though that error is actually printed, it does not end up as the response from admin-ajax.php.

Viewing 1 replies (of 1 total)
  • The topic ‘Ajax 500 Internal Server Error’ is closed to new replies.