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

时间:2022-10-08 08:38:45

In Safari only, why is the $_POST array empty when posting using a jQuery AJAX call?

仅在Safari中,为什么在使用jQuery AJAX调用发布时$ _POST数组为空?

IE, Firefox and Chrome all output correctly.

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>

The file target.php contains the following code:

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

<?php print_r($_POST); ?>

and outputs the following:

并输出以下内容:

Array
(
)

4 个解决方案

#1


0  

Try removing the ( and ) in data.

尝试删除(和)数据。

#2


0  

The problem could be related to iOS 6 caching certain post requests. Have a look at this post: ios caching post request responses.

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

You could test this by checking if you're using no Cache-Control headers or "Cache-Control: max-age=0" and removing them.

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

#3


0  

First of all you are setting the datatype to xml I guess this should be html since you're not getting xml as responce. see: http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests

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

quote : "Why is data an object in brackets?"

引用:“为什么数据是括号中的对象?”

also use async : true in your request if Mark roper is correct.

如果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));
            }
            });
        });

Just changed the success to : success: function(data) {alert(String(data));} EDIT: on http://peervantienen.com/*/in-safari-why-is-the-post-array-empty-after-jquery-ajax-call/ it gave me the same results in all browsers.

刚刚将成功改为:success:function(data){alert(String(data));}编辑:在http://peervantienen.com/*/in-safari-why-is-the-post-array-empty -after-jquery-ajax-call /它在所有浏览器中给出了相同的结果。

#4


0  

One of my colleagues found the answer:

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

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

Hope this helps other people...

希望这有助于其他人......

#1


0  

Try removing the ( and ) in data.

尝试删除(和)数据。

#2


0  

The problem could be related to iOS 6 caching certain post requests. Have a look at this post: ios caching post request responses.

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

You could test this by checking if you're using no Cache-Control headers or "Cache-Control: max-age=0" and removing them.

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

#3


0  

First of all you are setting the datatype to xml I guess this should be html since you're not getting xml as responce. see: http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests

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

quote : "Why is data an object in brackets?"

引用:“为什么数据是括号中的对象?”

also use async : true in your request if Mark roper is correct.

如果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));
            }
            });
        });

Just changed the success to : success: function(data) {alert(String(data));} EDIT: on http://peervantienen.com/*/in-safari-why-is-the-post-array-empty-after-jquery-ajax-call/ it gave me the same results in all browsers.

刚刚将成功改为:success:function(data){alert(String(data));}编辑:在http://peervantienen.com/*/in-safari-why-is-the-post-array-empty -after-jquery-ajax-call /它在所有浏览器中给出了相同的结果。

#4


0  

One of my colleagues found the answer:

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

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

Hope this helps other people...

希望这有助于其他人......