1

部屋は配列です

window.location = "booking_status.php?array="+ JSON.stringify(rooms);

javascriptからphpページのphpページに送信すると、そのようなページアドレスバーのurlの配列に格納されている完全な配列値が表示されます

http://localhost/zalawadi/booking_status.php?array=[ {%22id%22:10,%22rate%22:100} ]

URLに表示されるこのデータを防止したい%22id%22:10,%22rate%22:100

javascriptからphpページに配列データを送信する他の方法でphpページをデコードしています

4

4 に答える 4

3

URL にデータを表示せずに別のページにデータを送信する唯一の方法は、POST を使用することです。

基本的に、データを非表示のフォーム input に入れることができます:

<form method="post" id="form" action="booking_status.php">
    <input name="array" id="array" type="hidden" value="" />
</form>
<a href="" onclick="sendForm(); return false;">Send</a>
<script type="text/javascript">
    function sendForm(){
        document.getElementById('array').value = JSON.stringify(rooms);
        document.getElementById('form').submit(); //fixed syntax
    }
</script>
于 2013-09-03T15:00:39.660 に答える
0

POSTそれでは、代わりにデータだけではないのはなぜですか?

たとえば、次の場合jQuery:

$.ajax({
  type: "POST",
  url: "booking_status.php",
  data: JSON.stringify(rooms),
  success: // add success function here!
});

利点は、恐ろしい URL を渡さないことです。おまけに、この例も非同期であるため、ユーザーのブラウザーは更新されません。

フレームワーク以外のバージョン

を使用したくない場合は、次のようにオブジェクトjQueryを使用して、純粋な Javascript でこれを行うことができます。XMLHttpRequest

var url = "get_data.php";
var param = JSON.stringify(rooms);

var http = new XMLHttpRequest();
http.open("POST", url, true);


http.onreadystatechange = function() {//Call a function when the state changes.
    if(http.readyState == 4 && http.status == 200) {
    // Request has gone well. Add something here.
    }
}
http.send(param);
于 2013-09-03T15:00:16.687 に答える
0

POST リクエストを使用できますが、フォームを生成して送信する必要があります。

// assuming `rooms` already defined
var frm = document.createElement('form'), inp = document.createElement('input');
frm.action = "booking_status.php";
frm.method = "post";
inp.type = "hidden";
inp.name = "array";
inp.value = JSON.stringify(rooms);
frm.appendChild(inp);
document.body.appendChild(frm);
frm.submit();
于 2013-09-03T15:00:33.727 に答える