如何通过单击按钮调用 PHP


How to Call a PHP on the Click of a Button

我是PHP的新手。

我需要运行这个jQuery代码PHP

Class active只需将display:none更改为display:block

代码在这里 http://jsbin.com/weribi/1/

$(document).ready(function(){
  $(".cecutient-btn").click(function(){
    event.preventDefault();
    $(this).parent().find(".more-info-open")
    .slideToggle("slow")
    .toggleClass("active");
  });
});

我需要做什么?

点击事件进行 ajax 调用

学习,学习!从这里开始

$(document).ready(function(){
  $(".cecutient-btn").click(function(){
    event.preventDefault();
    $(this).parent().find(".more-info-open")
    .slideToggle("slow")
    .toggleClass("active");
    $.ajax({
      type: "GET",
      url: "yourFile.php", //your file .php
      data: data,
      success: function(data) {
      }
    });
  });
});

没有jquery的ajax调用[信息在这里]

function loadXMLDoc() {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else {
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 ) {
           if(xmlhttp.status == 200){
               document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
           }
           else if(xmlhttp.status == 400) {
              alert('There was an error 400')
           }
           else {
               alert('something else other than 200 was returned')
           }
        }
    }
    xmlhttp.open("GET", "ajax_info.txt", true);
    xmlhttp.send();
}

如果你想从点击事件运行php代码,你需要对你的php页面进行ajax调用。PHP 是一种服务器端语言,不能在浏览器上运行。

在此处查看 jQuery 的 AJAX 函数的文档

你想要类似的东西

$.ajax({
    url: "url/to/myPhpPage.php"
}).done(function() {
    //callback code here
});