plugins – Trouble with AJAX using GET

Question

I am creating a event calendar. It works fine on our Intranet fine, but when I copy the plugin to an external site, I keep getting the following:

Sorry, that didn’t work. Please try again or come back later. 500 Error. Internal Server Error.

Here is the code that calls the function:

<button id="prev" class="button" onclick="getPrevmonth()"> < </button>

Here is the Javascript/AJAX function: (I used a couple alerts to make sure this was running fine, and it seems to be)

function getPrevmonth() {
            
    var currentmonth = document.getElementById('currentmonth').value;
    var currentyear = document.getElementById('currentyear').value;
    
    if (currentmonth) {
        if (currentmonth == 0) {
            var newmonth = 11;
            var newyear = currentyear-1;
        } else {
            var newmonth = Number(currentmonth) - 1;
            var newyear = currentyear;
        }
        alert("month set =" + newmonth);
    } else {
        var date = new Date();
        var month = date.getMonth();
        var year = date.getFullYear();
        
        if (month == 0) {
            var newmonth = 11;
            var newyear = year-1;
        } else {
            var newmonth = month - 1;
            var newyear = year;
        }
    }
    
    ( function( $ ) {
        $.ajax({
            type: "GET", // use $_GET method to submit data
            url: CalendarScript.pluginsUrl + '/events/processcalendar.php', // where to submit the data
            data: {
                newmonth : newmonth, // PHP: $_GET['newmonth']
                newyear  : newyear, // PHP: $_GET['newyear']
            },
            success:function(data) {
                $( '#calendardiv' ).html( data ); // add HTML results to empty div
                $( '#currentmonth' ).val( newmonth );
                $( '#currentyear' ).val( newyear );
            },
            error: function(req, textStatus, errorThrown){
                //alert('Ooops, something happened: ' + textStatus + ' ' +errorThrown);
                $( '#calendardiv' ).html( req.responseText );
            }
        });
    } )( jQuery );
}

Ans this is the processcalendar.php. I removed all the code and just put in something simple to test if it was something in this code, but it is still displaying the above error:

<?php
require_once('../../../wp-load.php');
global $wpdb;

$newmonth = $_GET["newmonth"];

echo $newmonth;

Any help or advice is appreciated. Thanks in advance.

0
Darth Mikey D 4 months 2021-03-29T12:48:06-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse