admin管理员组文章数量:1296880
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.
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.
Share Improve this question asked Mar 29, 2021 at 17:48 Darth Mikey DDarth Mikey D 931 silver badge9 bronze badges 4- Check your error logs? – vancoder Commented Mar 29, 2021 at 18:22
- 3 You should not be using a standalone PHP file for AJAX, there's 2 APIs in WordPress dedicated to handling AJAX requests. Standalone PHP AJAX and form handlers have lots of problems and are extreme bad practice – Tom J Nowell ♦ Commented Mar 29, 2021 at 19:24
- I have very little experience using AJAX. Can you point me toward some examples? – Darth Mikey D Commented Mar 29, 2021 at 19:37
- AJAX in WordPress is a good place to start. – Pat J Commented Mar 30, 2021 at 20:59
1 Answer
Reset to default 0So, it turns out I'm an idiot. For some reason, Aptana changed what permissions files got uploaded with. I fixed that, and logged into the server to update the permissions on the files already uploaded, and it worked fine.
本文标签: pluginsTrouble with AJAX using GET
版权声明:本文标题:plugins - Trouble with AJAX using GET 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741646006a2390188.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论