当我从javascript发送数据到php文件时,它看起来不像它会从帖子中接收数据,我做错了什么?
//The javascript
$(document).ready(function() {
$("#send").click(function() {
var source1='test';
$.ajax({
type: "POST",
url: "test.php",
data: {source1: source1},
});
});
});
//The PHP file - test.php
<?php $test = $_POST['source1']; print $test; ?>
删除数据源后的最终,
。这会破坏你的JS。
如果这不能解决您的问题,请加载浏览器的开发人员工具,看看是否触发了XHR。
从那里调试会更容易。
其他一些事情:来源1应该有引号
用echo $test
或print_r($test);
代替print
。您可以使用这个简写来代替
var source1 = "test";
$.post( "test.php", { "source1": source1}, "json");