1

我想将 json 数据发送到 php 文件。当我将它作为查询字符串发送时,发送了一半的数据,当我以以下方式发送它时,根本什么都没有发送

 Ext.Ajax.request({
        url: 'GetData.php',
         params: {
            data:document.getElementById("jsonData").value

          },
       method: "POST",

        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function(xhr) {
       console.log(xhr)
        }
 });

我以不同的方式修改了我的 ajax 调用,但它总是发送 null。在发出 ajax 请求之前,我已经检查了我的隐藏字段“jsonData”中是否有数据。请帮助这里是json数据-

{"items":[{"text":"Table of Contents","items":[{"text":"Cover","source":"book/00__Cover.html","leaf":true,"items":"[]"},
{"text":"Introduction","source":"book/Introduction.html","leaf":true,"items":"[{\"text\":\"Me maps\",\"source\":\"book/Introduction.html#c000030\\\"\",\"leaf\":true},{\"text\":\"Spatial perspective\",\"source\":\"book/Introduction.html#c000031\\\"\",\"leaf\":true}]"},{"text":"Index","source":"book/Index.html","leaf":true,"items":"[]"}]},{"text":"My Study Guide","source":"studyguide.js","leaf":true},{"text":"Shared","source":"shared.js","leaf":true}]}
4

2 回答 2

1
    headers: { 'Content-Type': 'application/json' }, 
    jsonData: {
        document.getElementById("jsonData").value
    },

如果您更改这些内容但可能会删除,那应该可以工作

dataType: 'json',

以及。我从来没有用过,也不知道它是否存在你也不能设置字符集,它会以 utf-8 形式发送它,不管你做什么

编辑也记录 jsondata.val 就像我上面的人说的那样只是为了确保

编辑2

 Ext.Ajax.request({
        url: 'GetData.php',
        headers: { 'Content-Type': 'application/json' }, 
        jsonData: {
            document.getElementById("jsonData").value
        },
        method: "POST",
        dataType: 'json',
        success: function(xhr) {
            console.log(xhr);
        }
 });

你把你的代码改成这样了吗?你也试过记录你的失败错误吗?如果是这样,它会说什么。你错过了一个 ; 在你的成功功能中

于 2012-12-24T07:15:13.720 回答
0

我认为您需要将您的 ajax 调用更改为此(假设("jsonData").value确实包含一个 json 对象):

Ext.Ajax.request({
    url: 'GetData.php',
    jsonData: Ext.util.JSON.encode(document.getElementById("jsonData").value)
    method: "POST",
    success: function(xhr) {
      console.log(xhr)
    }
});

在这里阅读更多:http: //joekuan.wordpress.com/2010/12/06/posting-json-data-from-ext-js-to-php/

于 2012-12-24T07:11:31.653 回答