Javascript PHP/JS将订单详细信息记录到文本文件仅适用于chrome浏览器,而不适用于其他浏览器
我有一个简单的PHP文件,它将订单的详细信息记录到一个文本文件中 它使用form_向导在Drupal中的定制购物车上使用,form_向导将订单详细信息收集到cookie,然后通过PayPal处理订单 当用户单击PlaceOrder按钮时,日志文件将该订单信息保存为JSON对象 但是,如果用户使用Chrome,PHP文件似乎只记录文件的顺序。如果用户正在使用Safari,则不会追加日志 下面是PHP:Javascript PHP/JS将订单详细信息记录到文本文件仅适用于chrome浏览器,而不适用于其他浏览器,javascript,php,google-chrome,logging,safari,Javascript,Php,Google Chrome,Logging,Safari,我有一个简单的PHP文件,它将订单的详细信息记录到一个文本文件中 它使用form_向导在Drupal中的定制购物车上使用,form_向导将订单详细信息收集到cookie,然后通过PayPal处理订单 当用户单击PlaceOrder按钮时,日志文件将该订单信息保存为JSON对象 但是,如果用户使用Chrome,PHP文件似乎只记录文件的顺序。如果用户正在使用Safari,则不会追加日志 下面是PHP: <?php logcart(); function logcart() {
<?php
logcart();
function logcart() {
$file = 'cart.txt';
$today = date("F j, Y, g:i a");
$customer = $_COOKIE["address"];
$cart = $_COOKIE["votre_commande"];
$cart_contents = $today.PHP_EOL.$customer.PHP_EOL.$cart;
// Write the contents to the file,
// using the FILE_APPEND flag to append the content to the end of the file
// and the LOCK_EX flag to prevent anyone else writing to the file at the same
// time file_put_contents($file, $cart_contents, FILE_APPEND | LOCK_EX);
}
我不明白为什么会有问题。我看不出为什么它不能在其他浏览器上工作。我没有看到任何控制台错误
此外,正如您在上面所看到的,由于某些原因,当日志被附加到文件时,使用Chrome它会附加两次数据。这是一个次要的结果,但最好对文件进行清理,以便每个订单只记录一次订单详细信息
任何建议都将不胜感激。它依赖于浏览器这一事实意味着它不是PHP问题。PHP不关心用户使用什么客户端。@SecondRikudo我同意……这就是为什么我在Javascript聊天室上发布了这个问题。我的JS知识有限,因此任何帮助都将不胜感激。
function cartToLog() {
console.log('logging the cart!');
$.ajax({
type: "POST",
beforeSend: function (xhr) {
xhr.withCredentials = false;
},
crossDomain: true,
dataType: 'jsonp',
url: "http://example.com/modules/form_example/js/logcart.php",
headers: {
'Access-Control-Allow-Origin': '*'
},
contentType: 'application/json',
data: "",
success: function(msg) {
console.log(msg);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log(errorThrown);
}
});
}
Drupal.behaviors.select_paypal = {
attach: function(context) {
$('.paypal-button', context).once(function() {
$(this).click(function(e) {
if ($('#edit-tf-prenom').val() == '' ) { $('#edit-tf-prenom').addClass('error'); } else { $('#edit-tf-prenom').removeClass('error');}
if ($('#edit-tf-nom').val() == '' ) { $('#edit-tf-nom').addClass('error'); } else { $('#edit-tf-nom').removeClass('error');}
if ($('#edit-tf-adresse').val() == '' ) { $('#edit-tf-adresse').addClass('error'); } else { $('#edit-tf-adresse').removeClass('error');}
if ($('#edit-tf-code-postal').val() == '' ) { $('#edit-tf-code-postal').addClass('error'); } else { $('#edit-tf-code-postal').removeClass('error');}
if ($('#edit-tf-ville').val() == '' ) { $('#edit-tf-ville').addClass('error'); } else { $('#edit-tf-ville').removeClass('error');}
if ($('#edit-tf-pays').val() == '' ) { $('#edit-tf-pays').addClass('error'); } else { $('#edit-tf-pays').removeClass('error');}
if ($('#edit-tf-email').val() == '' ) { $('#edit-tf-email').addClass('error'); } else { $('#edit-tf-email').removeClass('error');}
if ($('#edit-tf-telephone').val() == '' ) { $('#edit-tf-telephone').addClass('error'); } else { $('#edit-tf-telephone').removeClass('error');}
if ($('#edit-tf-prenom2').val() == '' ) { $('#edit-tf-prenom2').addClass('error'); } else { $('#edit-tf-prenom2').removeClass('error');}
if ($('#edit-tf-nom2').val() == '' ) { $('#edit-tf-nom2').addClass('error'); } else { $('#edit-tf-nom2').removeClass('error');}
if ($('#edit-tf-adresse2').val() == '' ) { $('#edit-tf-adresse2').addClass('error'); } else { $('#edit-tf-adresse2').removeClass('error');}
if ($('#edit-tf-code-postal2').val() == '' ) { $('#edit-tf-code-postal2').addClass('error'); } else { $('#edit-tf-code-postal2').removeClass('error');}
if ($('#edit-tf-ville2').val() == '' ) { $('#edit-tf-ville2').addClass('error'); } else { $('#edit-tf-ville2').removeClass('error');}
if ($('#edit-tf-pays2').val() == '' ) { $('#edit-tf-pays2').addClass('error'); } else { $('#edit-tf-pays2').removeClass('error');}
if ($('#edit-tf-email2').val() == '' ) { $('#edit-tf-email2').addClass('error'); } else { $('#edit-tf-email2').removeClass('error');}
if ($('#edit-tf-telephone2').val() == '' ) { $('#edit-tf-telephone2').addClass('error'); } else { $('#edit-tf-telephone2').removeClass('error');}
if (!$.cookie('livraison')) {
$('.livraison-error-messages').html('<p class="error medmarginsides">Sélectionnez un mode de livraison');
e.preventDefault();
} else if ( ($('#edit-tf-prenom').val() == '') || ($('#edit-tf-nom').val() == '') || ($('#edit-tf-adresse').val() == '') || ($('#edit-tf-code-postal').val() == '') || ($('#edit-tf-ville').val() == '') || ($('#edit-tf-pays').val() == '') || ($('#edit-tf-email').val() == '') || ($('#edit-tf-telephone').val() == '') ) {
$('.facturation-error-messages').html('<p class="error medmarginsides">Les champs encadrés en rouge sont obligatoires');
e.preventDefault();
} else if ($.cookie('expediera')) {
if ( ($('#edit-tf-prenom2').val() == '') || ($('#edit-tf-nom2').val() == '') || ($('#edit-tf-adresse2').val() == '') || ($('#edit-tf-code-postal2').val() == '') || ($('#edit-tf-ville2').val() == '') || ($('#edit-tf-pays2').val() == '') || ($('#edit-tf-email2').val() == '') || ($('#edit-tf-telephone2').val() == '') ) {
$('.expediera-error-messages').html('<p class="error medmarginsides">Les champs encadrés en rouge sont obligatoires expediera');
e.preventDefault();
}
} else if (!$.cookie('conditions')) {
$('.conditions-error-messages').html('<p class="error medmarginsides">SVP, vérifiez que vous avez lu et approuver les conditions générales');
e.preventDefault();
} else {
deleteError('.facturation-error-messages');
deleteError('.expediera-error-messages');
// Reset cookies and return to start of order
$.cookie('reset', 'yes');
// Save address to cookie
address_array = [];
if ($.cookie('expediera')) {
adresse = $('#edit-tf-adresse2').val();
appartement = $('#edit-tf-appartement-suite2').val();
code_postal = $('#edit-tf-code-postal2').val();
ville = $('#edit-tf-ville2').val();
canton = $('#edit-tf-canton-province2').val();
pays = $('#edit-tf-pays2').val();
telephone = $('#edit-tf-telephone2').val();
instructions = $('#edit-instructions').val();
address_array.push({adresse: adresse, appartement: appartement, code_postal: code_postal, ville: ville, canton: canton, pays: pays, telephone: telephone, instructions: instructions});
address_json = JSON.stringify(address_array);
$.cookie('address', address_json);
} else {
adresse = $('#edit-tf-adresse').val();
appartement = $('#edit-tf-appartement-suite').val();
code_postal = $('#edit-tf-code-postal').val();
ville = $('#edit-tf-ville').val();
canton = $('#edit-tf-canton-province').val();
pays = $('#edit-tf-pays').val();
telephone = $('#edit-tf-telephone').val();
email = $('#edit-tf-email').val();
instructions = $('#edit-instructions').val();
address_array.push({adresse: adresse, appartement: appartement, code_postal: code_postal, ville: ville, canton: canton, pays: pays, telephone: telephone, email: email, instructions: instructions});
address_json = JSON.stringify(address_array);
$.cookie('address', address_json);
cartToLog();
}
}
});
});
}
}
January 2, 2015, 6:11 pm
[{"adresse":"49 some street","appartement":"","code_postal":"1227","ville":"Carouge","pays":"Suisse","telephone":"079 123 45 67","email":"user@example.com","instructions":""}]
[{"order":"Pack XS","price":"99.00 CHF","cat":"Cat1"},{"order":"1 CD/DVD","price":"10.00 CHF","cat":"Cat5"},{"order":"1 Lot","price":"2.00 CHF","cat":"Cat6"},{"order":"Postpac","price":"0.00 CHF","cat":"Cat7"}]January 2, 2015, 6:11 pm
[{"adresse":"49 some street","appartement":"","code_postal":"1227","ville":"Carouge","pays":"Suisse","telephone":"079 123 45 67","email":"user@example.com","instructions":""}]
[{"order":"Pack XS","price":"99.00 CHF","cat":"Cat1"},{"order":"1 CD/DVD","price":"10.00 CHF","cat":"Cat5"},{"order":"1 Lot","price":"2.00 CHF","cat":"Cat6"},{"order":"Postpac","price":"0.00 CHF","cat":"Cat7"}]