Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery$post()-方法似乎什么都不做_Jquery_Ajax - Fatal编程技术网

JQuery$post()-方法似乎什么都不做

JQuery$post()-方法似乎什么都不做,jquery,ajax,Jquery,Ajax,我有一个html/javascript前端和一个php后端,希望使用ajax将json stringarray从前端传输到后端。不幸的是,它不工作,我不知道为什么。以下代码不适用于我: <html> <head> <script src="http://code.jquery.com/jquery-2.1.3.js" type="text/javascript"></script> <script type="text/jav

我有一个html/javascript前端和一个php后端,希望使用ajax将json stringarray从前端传输到后端。不幸的是,它不工作,我不知道为什么。以下代码不适用于我:

<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>

函数sendData(){
$.post(“test.php”,{},函数(数据){
$(“#输出”).val(数据);
});
}

test.php文件如下所示:

<?php
     echo "this text has been send back";
?>

如果我是正确的,通过单击按钮,应该会显示来自ajax查询的响应,但什么也没有发生。我想有点不对劲,但我看不出问题出在哪里

致以最诚挚的问候,请参见下面的代码。不用

将函数更改为下面的值。不需要使用{}

 function sendData(){
        $.post("test.php",function(data){
            $("#output").html(data);
       });
    }

错的是你的jQuery。p标记不使用$.val();它使用$.html()。

如果不发送任何数据,则不需要{}。而.html(数据)的答案就是你为什么看不到答案的原因。val()用于输入类型
 function sendData(){
        $.post("test.php",function(data){
            $("#output").html(data);
       });
    }