0

Friends, i need the help for sending array to the querystring . just a simple html page.

var obj = [];
    obj[0] = {Guest:"Ramkumar", City: "Madurai", Mobile: "9578606320", Email: "bsrsms@gmail.com", Address:"first street" };
    obj[1] = {Guest:"Sathish", City: "Madurai", Mobile: "9578606320", Email: "bsrsms@gmail.com", Address:"first street" };
    obj[2] = {Guest:"Suresh", City: "Madurai", Mobile: "9578606320", Email: "bsrsms@gmail.com", Address:"first street" };
    obj[3] = {Guest:"Ganesh", City: "Madurai", Mobile: "9578606320", Email: "bsrsms@gmail.com", Address:"first street" };

var x = JSON.stringify(obj);


window.location = "view.html?Object=" + JSON.stingify(obj);

When redirect i got the error like this.. . Internal Server error.

atmd
  • 7,430
  • 2
  • 33
  • 64
Pikachu
  • 27
  • 1
  • 6
  • 3
    It's `stringify` not `stingify`, and the error is on the server, so it's probably not expecting whatever it is you're sending – adeneo Mar 17 '15 at 11:53
  • I'll have to expand [toSting](https://github.com/atmd83/toSting) with a stingify method – atmd Mar 17 '15 at 11:55
  • 1
    adeneo is right, plus, that window.location you can add "view.html?Object="+ x; you have already stringify the object – Zander Mar 17 '15 at 11:56
  • Everytime when you get `Internal Server error` look in your server `error_log` before any other actions. – tutankhamun Mar 17 '15 at 12:49

2 Answers2

1
var obj = [];
    obj[0] = {Guest:"Ramkumar", City: "Madurai", Mobile: "9578606320", Email: "bsrsms@gmail.com", Address:"first street" };
    obj[1] = {Guest:"Sathish", City: "Madurai", Mobile: "9578606320", Email: "bsrsms@gmail.com", Address:"first street" };
    obj[2] = {Guest:"Suresh", City: "Madurai", Mobile: "9578606320", Email: "bsrsms@gmail.com", Address:"first street" };
    obj[3] = {Guest:"Ganesh", City: "Madurai", Mobile: "9578606320", Email: "bsrsms@gmail.com", Address:"first street" };

var x = JSON.stringify(obj);


window.location = "view.html?Object=" + JSON.stingify(obj);

Contains an error.

window.location = "view.html?Object=" + JSON.stingify(obj);

should be

window.location = "view.html?Object=" + JSON.stringify(obj);

JSON.stringify, not JSON.stingify

Your server side is probably not expecting the faulty output of your code.

EDIT

As mentioned in the comments, you have already stringified your object into the variable x, so there's no need to stringify it again. Therefore you could also use

window.location = "view.html?Object=" + x;
Alex
  • 606
  • 11
  • 23
0

Try using encodeURIComponent to encode the URL properly.

var x = encodeURIComponent(JSON.stringify(obj));
window.location = "view.html?Object=" + x;

In addition to the stingify typo, that should be stringify.

Also, since the GET variable seems to be quite large, you may want to consider switching to POST. I recommend checking out maximum length of HTTP GET request?

Community
  • 1
  • 1
Vlad Preda
  • 9,780
  • 7
  • 36
  • 63