我得到一个服务器500错误与下面的代码。我还用测试文件测试了它,仍然有500个错误。文件设置为644。
这是Ajax代码
function paynlSubmitPayment(userid ,credits ,profile ,bankId) {
paynlSubmitForm = false;
var newwin = paynlPaymentPopup('/Paynl/paynl-loading.html');
var product = jQuery("input[name='selectedProduct']").val();
$.ajax({
type: "POST",
url: "/Paynl/paynl-api.php",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: {
mode:'startPayment',
product:product,
profile:profile,
idealBank:bankId,
userid:userid,
credits:credits
},
success: function(data) {
if('TRUE' == data.result) {
newwin.location.href = data.issuerUrl;
newwin.focus();
} else {
newwin.close();
alert(data.error);
}
},
error: function(){
newwin.close();
alert('Fail');
},
complete: function() {
paynlSubmitForm = true;
}
});
}
function paynlCheckFormSubmit() {
return paynlSubmitForm;
}
加载弹出工作,但它显示了错误'失败'部分。我也试过把整个url与http,但仍然没有成功。我可以张贴php文件,但似乎错误是在Ajax的某个地方,因为测试文件也没有工作。
编辑<?php
# Include classes
include realpath(dirname(__FILE__)) . '/Paynl/Paynl.php';
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/connect.php');
# Controleer of installer is doorlopen
if (!class_exists('PaynlConfigPPT') || !class_exists('PaynlConfigPPC')) {
trigger_error('Run installer first!', E_USER_ERROR);
die();
}
switch (strtoupper($_POST['mode'])) {
case 'STARTPAYMENT':
try {
# PPT transactie starten
$paynlPPT = new PaynlPPT();
$products = $paynlPPT->getProducts();
# Bepaal bedrag aan de hand van de producten in de
# config en het ID van het geselecteerde product
$transactionValue = $products[$_POST['product']]['price'];
# Bij ideal wordt een bank verwacht
if (array_key_exists('idealBank', $_POST)) {
if ((int) $_POST['idealBank'] <= 0) {
# geen bank geselecteerd voor doorsturen naar internetbankieren.
throw new PaynlException('Geen bank geselecteerd');
}
$idealBankId = (int) $_POST['idealBank'];
$selectedProfile = PaynlPPT::PROFILE_ID_IDEAL;
} else {
# Geen ideal, dus bankId=null
$idealBankId = null;
$selectedProfile = (int) $_POST['profile'];
}
# Transactie submitten bij Pay.nl
$paynlPPT->setProductId($_POST['product']);
$data = $paynlPPT->startTransaction($transactionValue, $selectedProfile, $idealBankId);
// CG - Insert Transaction Details
mysql_query("INSERT INTO transactions(transid, amount, userid, pakket, credits, betaald, uts) VALUES('".$data['orderId']."','" . $transactionValue . "', '".$_POST['userid']."', '" . $_POST['product'] . "', '".$_POST['credits']."', 0, " . time() . ");") or die(mysql_error());
// CG - Insert Transaction Details
} catch (PaynlException $e) {
$data = array(
'result' => 'FALSE',
'error' => $e->getMessage()
);
}
echo json_encode($data);
break;
}
你正在尝试从$_POST
读取数据,但如果你发送JSON, PHP将不会填充。
:
contentType: "application/json; charset=utf-8",
表示"此请求的内容是JSON"。PHP会相信你,不会填充$_POST
。
由于您实际上没有发送JSON,因此只需删除该行。
HTTP代码500表示服务器内部错误。这意味着PHP脚本中的某些内容正在崩溃。Ajax调用本身没有问题。
对AJAX返回的数据做一个console.log(data)
,并删除:contentType: "application/json; charset=utf-8"
在AJAX选项。
这样,PHP错误信息将显示在控制台中。