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: "[email protected]", Address:"first street" };
    obj[1] = {Guest:"Sathish", City: "Madurai", Mobile: "9578606320", Email: "[email protected]", Address:"first street" };
    obj[2] = {Guest:"Suresh", City: "Madurai", Mobile: "9578606320", Email: "[email protected]", Address:"first street" };
    obj[3] = {Guest:"Ganesh", City: "Madurai", Mobile: "9578606320", Email: "[email protected]", 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.

4
  • 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 Commented Mar 17, 2015 at 11:53
  • I'll have to expand toSting with a stingify method Commented Mar 17, 2015 at 11:55
  • 1
    adeneo is right, plus, that window.location you can add "view.html?Object="+ x; you have already stringify the object Commented Mar 17, 2015 at 11:56
  • Everytime when you get Internal Server error look in your server error_log before any other actions. Commented Mar 17, 2015 at 12:49

2 Answers 2

1
var obj = [];
    obj[0] = {Guest:"Ramkumar", City: "Madurai", Mobile: "9578606320", Email: "[email protected]", Address:"first street" };
    obj[1] = {Guest:"Sathish", City: "Madurai", Mobile: "9578606320", Email: "[email protected]", Address:"first street" };
    obj[2] = {Guest:"Suresh", City: "Madurai", Mobile: "9578606320", Email: "[email protected]", Address:"first street" };
    obj[3] = {Guest:"Ganesh", City: "Madurai", Mobile: "9578606320", Email: "[email protected]", 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;
Sign up to request clarification or add additional context in comments.

2 Comments

...and I suggest to escape url
Can you please let us see the server side, @Pikachu?
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?

2 Comments

What error_log says about this? Perhaps there is error in other place.
@Pikachu: Internal server error is a server error - as the name suggests, and not related to the JS you posted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.