1

Rooms are an array

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

sending from javascript to php page on php page url show full array value which are store in array in page address bar url like that

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

I want to prevent this data which show in url %22id%22:10,%22rate%22:100

I am decoding on php page any other way to send array data from javascript to php page

1
  • Use the POST method instead. Commented Sep 3, 2013 at 14:59

4 Answers 4

3

The only way to send data to another page without showing them in the url is to use POST.

Basically, you can put your data into an invisible form 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>
Sign up to request clarification or add additional context in comments.

1 Comment

You are welcome. If it solved your problem, please mark my answer as accepted by clicking on the grey "check" icon below the vote count. Thx
1

You can use a hidden form and the post method. Then you would use $_POST instead of $_GET.

<form action="script.php" onsubmit="this.firstChild.value=JSON.stringify(value);">
    <input type="hidden" value="" />
    <a href="javascript:this.form.submit();">Link text</a>
</form>

Comments

0

You can use a POST request, however this would require generating and submitting a form:

// 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();

Comments

0

Why not just POST the data instead then?

For example, with jQuery:

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

The advantage is you're not passing some horrific URL. As an added bonus, this example is also asynchronous, so the user doesn't see any refresh in their browser.

Non-Framework Version

If you don't wish to use jQuery, you can do this with pure Javascript, using the XMLHttpRequest object, like so:

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

3 Comments

Do you see a jQuery tag anywhere in this question?
Oh hello captain hostile. I thought it would be a suggestion.
i don;t know much about this http.onreadystagechange i mostly use jquery post method

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.