Привет Я пытаюсь сделать HTML-форму и должен проверить ее перед выполнением действия формы. Но ответ AJAX всегда возвращает пустое сообщение?jQuery Ответ AJAX всегда возвращает пустое сообщение
$(function(){
$("#ajax-payment-form input[type='submit']").click(function(e) {
// Prevent form submission
e.preventDefault();
// Serialize data, make AJAX call
var str = $(this).serialize();
$.ajax({
type: "POST",
url: templateDir+"/payment_form/payment_process.php",
data: str,
context: this
}).done(function(msg) {
if(msg == 'OK') {
console.log('Validation passed, will submit form');
$(this).closest('form').submit();
} else {
console.log(msg);
}
}).fail(function() {
// Catch ajax errors here
console.log('AJAX error');
});
});
});
PHP:
$post = (!empty($_POST)) ? true : false;
if ($post) {
$orderid = stripslashes($_POST['orderid']);
$amount = stripslashes($_POST['amount']);
$betingelser = stripslashes($_POST['betingelser']);
$error = ''; // Check ordreid
if (!$orderid) {
$error. = 'Venligst indtast dit ordreid.<br />';
} // Check amount
if (!$amount) {
$error. = 'Venligst indtast et beløb.<br />';
}
if (!$error) {
echo 'OK';
} else {
echo '<div class="notification_error">'.$error.
'</div>';
}
}
Может кто-нибудь сказать мне, что случилось?
вы можете показать мне свой код PHP для payment_process.php –
успеха является устаревшим? – thar
@AbdulBasit yes here: $ post = (! Empty ($ _ POST))? true: false; if ($ post) { \t $ orderid = stripslashes ($ _ POST ['orderid']); \t $ amount = stripslashes ($ _ POST ['amount']); \t $ betingelser = stripslashes ($ _ POST ['betingelser']); \t $ error = ''; \t // Проверка ordreid \t если (! $ OrderID) \t { \t $ ошибка. = «Venligst indtast ДИТ ordreid.
'; \t} \t // Проверить количество \t если (! $ Сумма) \t { \t $ ошибка. = «Venligst indtast и др beløb.
'; \t} \t если ($ ошибка!) \t { \t \t эхо 'OK'; \t} \t еще \t { \t \t эхо '