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 リクエストを行う前に、hiddenfield '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',

同じように。私はそれを使用したことがなく、それが存在するかどうかもわかりませんまた、文字セットを設定することはできません。

念のために上の人が言ったように、編集も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呼び出しをこれに変更する必要があると思います(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/

于 2012-12-24T07:11:31.653 に答える