I have the following jQuery for doing an Ajax call and it works fine:

jQuery(document).ready( function($){
$( "#mystatus" ).change(runMyStatus);

 function runMyStatus() {
  var mystatus = this.value;
  var data = {
        'action': 'bikeride_mystatus_function',
        'mystatus': mystatus,
        // 'rideID' : 123,
        'nonce': frontEndAjax.nonce

   var ajaxRequest = $.ajax({
       url: frontEndAjax.ajaxurl,
       type: "post",
       data: data
   ajaxRequest.done(function(response) {
   ajaxRequest.fail(function(jqXHR, textStatus, exception) {
     alert('Error.\n' + jqXHR.status + ' ::' + textStatus + ' ::' + exception);
 } // end runMyStatus
// end document ready

If I uncomment the line with rideID then it fails with a "500" status (I tried putting 123 in quotes but it made no difference). If I change the type from "post" to "get" then it works. This error occurs even with no plugins enabled and using the twentyseventeen theme. Any idea what is causing the error?

  • 1
    I think the issue is caused by or lies within your server-side AJAX handler/function. You should check its code and confirm whether the request method should be GET or POST (it's the type property used in the data object for your $.ajax() call). – Sally CJ Mar 10 '19 at 23:42
  • 1
    500 is an Internal Server Error, so would be caused by the PHP function used to handle the request. Can you include this in your question. – Jacob Peattie Mar 11 '19 at 1:41
  • Try replacing type: "post" with method: 'POST' – Aparna_29 Mar 11 '19 at 7:50
  • Hi Jacob, You're correct the 500 indicates something in the PHP function failed. If I comment out some of the code in the php function then it works. I just need to fix the php code. Thanks! – Jonathan Eiseman Mar 11 '19 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.