3
data.push({
    name: name,
    age: age,
    address: address,
    contactnumber: contactnumber

});

var url = '../reports/student.php?data='+data;
window.open(url, '_blank');

../reports/student.php?data=[object%20Object]

Above is an object i want to send to another page so i can retrieve it and use it on the next page to generate a report. The url is looking like the one above i am not sure if this is possible and if possible how can i get the value of each data in the object.If not possible please point me to the right direction any idea is ap

1
  • 2
    Use POST with data as JSON in the body. Commented Apr 29, 2015 at 8:15

2 Answers 2

8

if you definetly want to use GET request, use JSON.stringify:

var url = '../reports/student.php?data='+ encodeURIComponent(JSON.stringify(data));

But better way will be a POST request.

You also can use jQuery.param():

var data = {
  name: 'yourname',
  age: 1,
}

var params = jQuery.param(data) // 'name=yourname&age=1'
var url = '../reports/student.php?'+ params;
Sign up to request clarification or add additional context in comments.

5 Comments

it is ok if i dont stringify the data before sending i mean i want to do all retrieving in the next page?i mean i dont want to put stingify in the sending of data in url is it possible and how can i get the data now that i have sent it using jquery not php
my question is how will i get the value now in second page?
there is simple function for parsing get params by JS stackoverflow.com/questions/901115/…
should i pass the entire url to the function of just the data?
for get a data param you call like this: getParameterByName('data')
1

jQuery.param():

Create a serialized representation of an array, a plain object, or a jQuery object suitable for use in a URL query string or Ajax request. In case a jQuery object is passed, it should contain input elements with name/value properties.

The doc also states, that

If the object passed is in an Array, it must be an array of objects in the format returned by .serializeArray()

So in your case:

var url = '../reports/student.php?' + jQuery.param(serializeArray(data));

To unserialize you should use jQuery BBQ's deparam function, as per cce's answer in this SO question: The $.param( ) inverse function in JavaScript / jQuery.

2 Comments

how can i retrieve these value in the second page?
what i am getting in url is ?data=undefined=

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.