リダイレクトページなしでjquery POSTを使用して大きなデータを送信する方法を知りたいですか? モバイルチャットを作成し、ユーザーアプリとサーバーを接続するプロジェクトがあり、JSON を使用しています。jsonGet が大きなデータを処理できないことがわかっているため、これは jquery get json スクリプトのようです。
注: bigNumber には 8000 文字あります。
$.getJSON('process.php?input='+bigNumber, function(data) {
$.each(data.Chats, function(i,output)
{
$("#data").append(output.chat);
});
});
これは、getJSON を使用して大きな数を送信したときに得られるものです: 414 (Request-URI Too Large)
というわけで、bigNumberを送信した後、process.phpからjsonデータとしてレスポンスを取得し、htmlのbodyに追加します。
//--- これが私のコードです。
htmlファイル
<script src="jquery.min.js"></script>
<script>
$(function(){
$("#senddata").click(function() {
$.ajax({
dataType: "json",
url: "process.php",
data: { input:$("#bigNumber").val() },
success: function(data) {
$.each(data.Chats, function(i,output)
{
$("#data").append(output.key);
});
},
method: "POST"
});
});
});
</script>
<div id="data"></div>
<input type="text" id="bigNumber"/>
<button id="senddata">Send</button>
これはprocess.phpです
header('Content-type: application/json');
$key = $_POST["input"];
$simpan_array = array();
$chat = array();
$chat["key"] = $key;
array_push($simpan_array, $chat);
echo json_encode(array("Chats" => $simpan_array));
テキストボックスに入力して「送信」ボタンを押しても、何も起こりません。どうしたの?
今調べたところ、process.php に表示されている json 形式のエラーでした。