【问题标题】:I want to include a php code in a javascript function [duplicate]我想在javascript函数中包含一个php代码[重复]
【发布时间】:2019-10-06 21:55:00
【问题描述】:

我有一个< a ... onclick='show(); / a >。我想将我的 php 代码添加到 js 函数中,我的意思是点击后获得操作。

include($_SERVER['DOCUMENT_ROOT'] . '/model/action.php');
?>

我要把php代码放到这个脚本里

<script>
 document.getElementById("show").onclick = function() {show()};
 function show() {
  document.getElementById("numb").style.display="block";

<<<HERE>>>

}

</script>

【问题讨论】:

  • 这里有什么问题?你的尝试成功了吗?

标签: javascript php


【解决方案1】:

加上jQuery,你可以使用ajax函数来调用php脚本

<script>
$.ajax(
  'request_ajax_data.php',
  {
      success: function(data) {
        alert('AJAX call was successful!');
        alert('Data from the server' + data);
      },
      error: function() {
        alert('There was some error performing the AJAX call!');
      }
   }
);
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-11
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-26
    • 2016-06-26
    • 2012-02-05
    • 2014-08-08
    相关资源
    最近更新 更多