无法使d3.xml正确开机自检 [英] can't get d3.xml to POST correctly

查看:82
本文介绍了无法使d3.xml正确开机自检的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过AJAX/d3.xml将一些Vars发布/获取到php文件,但是php中的print_r($ _ POST/$ _ GET)告诉我它们是空的.甚至 doc 上的示例也不适用于我.

I tried to POST/GET some Vars to a php-file via AJAX/d3.xml, but a print_r($_POST/$_GET) inside the php, tells me they're empty. Even the example on the doc won't work for me.

d3.xml("xxx.php")
    .header("Content-Type", "application/x-www-form-url-encoded")
    /*
        .get("a=2&b=3", function(error, data) {
      console.log(error);
    })
        */
        .post("a=2&b=3", function(error, data) {
      console.log(error);
    })
    .on("load", createTable(data));

控制台告诉我有一个POST请求,但是在POST下(在Firefox上而不是在Chrome上),它在一行"a = 2& b = 3"中列出了Vars,而不是
a = 2
b = 3
像往常一样.
我没有得到什么?

The console tells me that there is a POST request but under POST (on Firefox, not on Chrome) it lists the Vars in one line "a=2&b=3", instead of
a = 2
b = 3
as it usually does.
What is it that I'm not getting?

推荐答案

首先,对注释中的混淆表示歉意.我一直在寻找d3的旧版本的源代码.在较新的代码中,的确确实是,如果不提供对d3.xml的回调,它将返回一个xhr请求,您可以直接对其进行配置. (如果您提供了回调,它将像以前一样立即执行GET.)

First, apologies for the confusion in the comments. I was looking at the source for an old version of d3. In the newer code, it is indeed true that if you do not provide a callback to d3.xml it returns an xhr request that you can configure directly. (If you do provide a callback, it executes a GET right away as before).

您会讨厌这个,所以请做好准备. :)您的问题是因为Content-Type标头中有一个破折号.你有:

You're going to hate this, so get ready. :) Your issue is because you have an extra dash in your Content-Type header. You have:

application/x-www-form-url-encoded

但应该是

application/x-www-form-urlencoded

在Firefox中查看jsfiddle的修改版本,我看到参数按预期显示在列表视图中: http://jsfiddle.net/WaT6r/3/

Looking at a modified version of your jsfiddle in Firefox, I see the arguments show up in the list view as expected: http://jsfiddle.net/WaT6r/3/

这篇关于无法使d3.xml正确开机自检的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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