jquery - jQuery + Javascript + php
问题描述
我的javascript按钮调用一个javascript函数,该函数内部有ajax,ajax调用一个php脚本文件,php文件写入一个文本文件。
我的问题,本地一切正常的 php 写在一个 OK 文件中。另一方面,当我放到网站上时,行为会改变结果,调用 php 脚本文件的 ajax 函数不再写入或被触发。
纽扣 :
<li><a href="javascript:callfunction('button Offre De Service');">Offre De Services</a></li>
等
<a href="javascript:callfunctions('connexionsecure','button Connection Secure');" class="bouton_rouge2">Connexion Sécurisée/Secure <img src="images/flecheblanchedroite.png" alt="flecheblanchedroite02" /></a>
这是我的 javascript 和 ajax 脚本:
/**
* Call Function
*/
function callfunction(id_logbutton)
{
location="fr_offre_de_services.php";
logbutton(id_logbutton);
}
/**
* Call Functions
*/
function callfunctions(id_toggle,id_logbutton)
{
toggle(id_toggle);
logbutton(id_logbutton);
}
/**
* Show or hide an page element...
*/
function toggle(id)
{
var elem = document.getElementById(id);
var elem2 = document.getElementById("connexionsecure");
var elem3 = document.getElementById("systemcaisse");
if (elem.style.display == "none") {
elem.style.display = "block";
}
else {
elem.style.display = "none";
}
if (elem2.style.display == "block" && elem3.style.display == "block") {
if (id == "connexionsecure") elem3.style.display = "none";
if (id == "systemcaisse") elem2.style.display = "none";
}
}
/**
* Connexionsecure...
*/
function logbutton(id)
{
// See logsecure.php
// var VarJSCRIPT = 5;
// $.get("logsecure.php", {VarPHP: VarJSCRIPT});
if (location.protocol == "https:")
{
if (id == "button Connection Secure") $.post("logbutton.php", {logbutton: "https Button Connection Secure"}, alert("TEST NCS http... "));
if (id == "button Offre De Service") $.post("logbutton.php", {logbutton: "https Button Offre De Service"}, alert("TEST ODS https... "));
}
else if (location.protocol == "http:")
{
if (id == "button Connection Secure") $.post("logbutton.php", {logbutton: "http Button Connection Secure"}, alert("TEST BCS http... "));
if (id == "button Offre De Service") $.post("logbutton.php", {logbutton: "http Button Offre De Service"}, alert("TEST ODS http... "));
}
}
这是我的 PHP 脚本:
<?php
header("Expires: 0");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
$button = $_POST["logbutton"];
//echo "Display : " .$button;
$file_log=fopen("1234/logbutton.txt", "a+");
if($file_log == false) die("La création du fichier a échoué");
$date_log = date("d/m/Y H:i:s");
$log = "Log Button --> " .$button. " " .$date_log."\r\n";
fwrite($file_log, $log);
fclose($file_log);
exit();
?>
如果有人有想法
亲切地
解决方案
推荐阅读
- python - 如何在 Pandas 中创建索引列名和循环?
- spring - Spring Boot - 编辑数据
- css - Bootstrap中的垂直对齐中心和匹配高度
- sql - 仅在 BigQuery 中更改月份和日期
- python - 查找将 Numpy 数组映射到另一个数组的索引
- javascript - 渲染许多元素时反应很慢
- java - 在 Activity 范围内声明值时 Android Studio 抛出错误
- html - 如何在 Bootstrap 中更改此导航栏中的文本颜色?
- servlets - Eclipse 中的 Servlet:请求的资源 [/Register/] 不可用
- react-native - 为什么 Xcode 12 更新后 react-native 应用程序中的图像不渲染