我有一个html / javascript前端和一个php后端,并希望从我的前端传输一个json-stringarray到ajax的后端。不幸的是,它不起作用,我不知道为什么。以下代码对我不起作用:
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.3.js" type="text/javascript"></script>
<script type="text/javascript">
function sendData(){
$.post("test.php", {}, function(data){
$("#output").val(data);
});
}
</script>
</head>
<body>
<input type="button" value="send" onclick="sendData()">
<p id="output"></p>
</body>
test.php文件如下所示:
<?php
echo "this text has been send back";
?>
如果我是正确的,通过单击按钮,应该显示来自ajax查询的响应,但没有任何反应。我想有些事情是错的,但我无法看出问题所在。
祝你好运