2012-12-24 83 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是否可以加帖 –