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:
- User changes something on plugin-page.
- The change is registered through JavaScript (jQuery).
- a jQuery.Post call is made to a function named ajax_callback, as seen below.
- The call tries to send two variables to the function: ‘caseType’ and ‘data’.
- 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) { $("#result").html(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']; print_r($data); break; case "2": $data = $_POST['data']; print_r($data); break; }
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)
Viewing 1 replies (of 1 total)
- The topic ‘Ajax 500 Internal Server Error’ is closed to new replies.