首页 > 解决方案 > 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();

?>

如果有人有想法

亲切地

标签: jquery

解决方案


推荐阅读