2012-12-24 85 views
1

我想发送json数据到php文件。当我把它作为查询字符串它,一半的数据被发送,当我以下列方式则没有在所有json数据通过ajax请求未被发送

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调用但它总是发送空。我已经检查过我的hiddenfield'jsonData'有数据在发出ajax请求之前。请帮助 这里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}]} 
+1

你能告诉我们'jsonData'吗? –

+0

您是否尝试过console.log(document.getElementById('jsonData')。的值只是Ext.Ajax.request之前的一行,这将帮助您查看数据是否被反过来检查您的json数据是否正确格式 –

+0

我检查了它在隐藏字段中的数据 - – Annie

回答

0

我想你需要你的AJAX调用改变这个(asuming ("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/

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

应该工作如果你改变这些,但也许删除

dataType: 'json', 

也。香港专业教育学院从未使用过,不知道这是否exsists 您也可以不设置字符集是将其作为你做什么

编辑UTF-8 reguardless也登录jsondata.val像上面的人我刚才说的做确保

EDIT2

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

你改变你的代码来读取这个样子?你有没有尝试记录你的失败错误?如果是的话,它说什么。你错过了一个;在你的成功功能

+0

50kb是否可以加帖 –