将数组发送到querystring

将数组发送到querystring

朋友,我需要将数组发送到querystring的帮助。只是一个简单的html页面。


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



  重定向时出现这样的错误。内部服务器错误。

最佳答案

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


包含错误。

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


应该

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


JSON.stringify,而不是JSON.stingify

您的服务器端可能不会期望代码输出错误。

编辑

如注释中所述,您已经将对象字符串化为变量x,因此无需再次对其进行字符串化。因此,您也可以使用

window.location = "view.html?Object=" + x;

关于javascript - 如何将数组发送到querystring,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29098367/

10-11 23:46