在Safari中,为什么jQuery AJAX调用后$_POST数组为空?

In Safari, why is the $_POST array empty after jQuery AJAX call?

本文关键字:POST 数组 调用 Safari 为什么 AJAX jQuery      更新时间:2023-09-26

在Safari只有,为什么是$_POST数组空时张贴使用jQuery AJAX调用?

IE, Firefox和Chrome都能正确输出。

<html>
<head>
    <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(
            function()
            {
                $.ajax(
                {
                    type: "POST",
                    url: "target.php",
                    dataType: "xml",
                    data: ({
                        'param1': 'param1'
                    }),
                    success: function()
                    {
                    }
                });
            });
    </script>
    <title></title>
</head>
<body>
</body>
</html>

文件target.php包含如下代码:

<?php print_r($_POST); ?>

并输出如下内容:

Array
(
)

尝试删除data中的()

这个问题可能与iOS 6缓存某些post请求有关。看看这篇文章:ios缓存post请求响应。

你可以通过检查是否没有使用Cache-Control头或"Cache-Control: max-age=0"并删除它们来测试这一点。

首先你设置的数据类型为xml,我猜这应该是html,因为你没有得到xml作为响应。参见:http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests

quote: "为什么data是括号中的对象?"

如果Mark roper是正确的,

也可以在请求中使用async: true。

 $(document).ready(
        function()
        {
            $.ajax(
            {
                type: "POST",
                url: "target.php",
                async :true,
                dataType: "html",
                data: {
                    'param1': 'param1'
                },
                success: function(data) {
            alert(String(data));
            }
            });
        });

把success改成:success: function(data) {alert(String(data));}编辑:在http://peervantienen.com/Stackoverflow/in-safari-why-is-the-post-array-empty-after-jquery-ajax-call/上它给了我相同的结果在所有浏览器

我的一个同事找到了答案:

http://forums.iis.net/post/1999417.aspx