通过 WinJS.XHR 发布 JSON 对象 [英] Posting JSON object through WinJS.XHR

查看:31
本文介绍了通过 WinJS.XHR 发布 JSON 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将数据从 WinJS.xhr 发布到 PHP 脚本时遇到了一些问题."obj" 是一个字符串化的 JSON 对象

I'm having abit of problems posting data from WinJS.xhr to a PHP script. "obj" is a stringified JSON object

WinJS.xhr({
            type: "POST",
            url: dataUrl,
            headers: { "Content-type": "application/x-www-form-urlencoded" },
            data: obj,
        })

然而,$_POST 变量始终为空.

However the $_POST variable is always empty.

我试过改变内容类型,并转义对象但没有运气:(

I've tried changing content-types, and escaping the object but no luck :(

推荐答案

想出了一个解决方案.

如果有人遇到同样的问题,我通过从 xhr 中删除标题并使用此代码在服务器端获取发布数据来解决问题:

Incase anyone has the same problem i got it working by removing headers from the xhr, and getting the post data @ server side with this code:

$data = file_get_contents('php://input');
$data = (array) json_decode($data);

这篇关于通过 WinJS.XHR 发布 JSON 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆