【发布时间】:2017-11-21 07:27:53
【问题描述】:
我想调用php函数,同时调用该函数我需要传递参数,当点击一些文本时,它必须调用名为test()的方法; 如何做到这一点。
我对 ajax 一无所知。我已使用此代码进行尝试。尝试我使用了简单的代码,但它也无法正常工作。
这是 Ajax.html 文件
<!DOCTYPE html>
<html>
<head>
<body>
<p>Click Me</p>
<script>
$(document).ready(function() {
$("p").click(function(){
$.ajax({
url:"script.php", //the page containing php script
type: "POST", //request type
success:function(result){
alert(result);
}
});
});
})
</script>
</body>
</head>
</html>
script.php 包含,
<?php
function test(){
echo "Hello";
}
?>
当用户单击某些文本时如何调用 php 函数。我必须调用该 test() 方法。谁能帮帮我?
【问题讨论】:
-
添加
dataType:'Text' -
在你的 script.php 中添加
test(); -
在我的代码中,我只需要在之前关闭 标签。
-
你需要先包含jquery库文件。 learn.jquery.com/about-jquery/how-jquery-works
标签: javascript php jquery html ajax