Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
 
Use the POST method instead. –  Loz Cherone Sep 3 at 14:59
add comment

4 Answers

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();
    }
</script>
share|improve this answer
 
thanks its usefull for me......... –  santosh vishwakarma Sep 12 at 13:43
 
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 –  Scalpweb Sep 12 at 13:45
add comment

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>
share|improve this answer
 
thanks its easy to use... –  santosh vishwakarma Sep 12 at 13:43
add comment

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();
share|improve this answer
 
it to trick for me could you explain me.... –  santosh vishwakarma Sep 12 at 13:45
 
What's not to get? Just read the code, it's almost plain English... –  Niet the Dark Absol Sep 12 at 14:16
add comment

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);
share|improve this answer
 
Do you see a jQuery tag anywhere in this question? –  Niet the Dark Absol Sep 3 at 15:00
 
Oh hello captain hostile. I thought it would be a suggestion. –  Chris Sep 3 at 15:02
 
i don;t know much about this http.onreadystagechange i mostly use jquery post method –  santosh vishwakarma Sep 12 at 13:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.