简体   繁体   English

jQuery .load,Post参数,未通过本地php服务器发送

[英]Jquery .load, Post parameters, not being sent over local php server

I have two files, test.php 我有两个文件,test.php

<html>
   <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head>
<body>
    <div id="status">LOADING</div>
    <br/>
    <div id="div1"></div>
    <br/>
    <br/>
    <div id="div2"></div>
    <script>
        $( "#div1" ).load( "sanity.php", "key=value"); // sent with GET
        $( "#div2" ).load( "sanity.php", {"key" : "value" }); // sent with POST
        $('#status').html("done");
    </script>
</body>
</html>

and sanity.php 和sanity.php

SOF
<table>
    <?php

    echo "<br/>";
    echo "POST:";
    var_dump($_POST);

    echo "<br/>";
    echo "GET:";
    var_dump($_GET);

    echo "<br/>";
    ?>
</table>
EOF

When I run them on my webserver, I get the (expected!) output, 当我在网络服务器上运行它们时,得到(预期!)输出,

done

SOF 
POST:array(0) { } 
GET:array(1) { ["key"]=> string(5) "value" } 
EOF


SOF 
POST:array(1) { ["key"]=> string(5) "value" } 
GET:array(0) { } 
EOF

But when I run them locally, I get 但是当我在本地运行它们时,我得到了

done

SOF 
POST:array(0) { } 
GET:array(1) { ["key"]=> string(5) "value" } 
EOF


SOF 
POST:array(0) { } 
GET:array(0) { } 
EOF

From LOADING turning into "done", I can see that the jQuery is running. 从LOADING变成“ done”,我可以看到jQuery正在运行。 The load is sending GET and POST depending on the format of the data being passed doc , ie 负载正在发送GET和POST,具体取决于传递给doc的数据的格式,即

"key=value" - GET request
{"key" : "value"} - POST request

This has obviously something to do with the local PHP server I'm running, but I have no idea where to start looking, as I've never experienced anything like this before. 显然,这与我正在运行的本地PHP服务器有关,但是我不知道从哪里开始寻找,因为我以前从未经历过这样的事情。 I've tried searching for "local php server post not working", with variations including "XAMPP" and "intellij". 我尝试搜索“本地php服务器帖子不起作用”,并带有“ XAMPP”和“ intellij”等变体。

Implied, I'm using XAMPP, with PHP 7.0 interpreter in Intellij. 暗示,我在Intellij中使用XAMPP和PHP 7.0解释器。

The headers being sent on the local server is almost identical to the ones being sent on the webserver, so the data is being passed, but it's simply not being picked up. 在本地服务器上发送的标头与在Web服务器上发送的标头几乎相同,因此数据正在传递,但根本没有被拾取。

Thank you! 谢谢!

EDIT: the "enable_post_data_reading" directive in php.ini is enabled/on 编辑:启用/启用“ enable_post_data_reading”指令在php.ini中

Apologies, it seems to be a standing bug in PHP Storm and Intellij IDEA, using the built in PHP server. 抱歉,使用内置的PHP服务器,这似乎是PHP Storm和Intellij IDEA中的一个常设错误。

See: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206999125-PhPStorm-10-does-not-allow-POST-method?page=1 参见: https : //intellij-support.jetbrains.com/hc/en-us/community/posts/206999125-PhPStorm-10-does-not-allow-POST-method?page=1

It seems it can be solved by using the xampp php server. 看来可以使用xampp php服务器解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM