2 回答
TA贡献1815条经验 获得超6个赞
你使用 XMLHttpRequest 的方式不对。您应该使用 2 个不同的页面:调用者 (index.php) 和异步脚本 (tempo.php) 更正您当前的调用者页面: index.php : • 使用不带任何参数的 url:
url="tempo.php"
• 一起发送您的两个参数:
req.send("a="+dayName+"&b="+dayName);
要调试异步页面:tempo.php,只需在 tempo.php 顶部添加一个伪造的 get_parameter:
a = a_possible_value_for_a
然后直接在浏览器中调用 tempo.php(没有你的 ajax 页面)
TA贡献1828条经验 获得超6个赞
从 HTML 文件发送的请求。
发送过程一:
$(document).on("click","#btn1",function(){
var data = $(this).val();
/* ajax request sent start */
$.ajax({
method:"post",
url:"phpFileName.php",
data:{backendPostName:data},
dataType:"json",
success:function(response){
/* Logic implemented here */
}
});
/* ajax request sent end*/
});
根据你的html结构发送过程二:
function clickMe(data){
var data = $(this).val();
/* ajax request sent start */
$.ajax({
method:"post",
url:"phpFileName.php",
data:{backendPostName:data},
dataType:"json",
success:function(response) {
/* Logic Implementation here */
}
});
/* ajax request sent end*/
}
当您想在 php 文件中接收此发送数据时。
首先通过php“isset()”函数检查是否找到这个名字
下面的例子:
php 文件:
<?php
if(isset($_POST['backendPostName'])){
$customName = $_POST['backendPostName'];
/*
store or other logic implement here .
if you wants to echo html then echo "success"; or your choice
if you wants to return json data then return json_encode(["result"=>1]);
*/
/* For HTML Return */
echo "<h1>Success</h1";
/*For Json return */
echo json_encode(["result"=>1]);
}
?>
- 2 回答
- 0 关注
- 171 浏览
添加回答
举报