1

so I am rather new to the whole .post() experience with jquery.

I have only experience POSTing input values so far. What I want to do is POST an array.

which is a standard array of a list of numbers. The end goal being: performing a query with these values.

Could somebody explain to me very basically how using JQuery .post() I can post my array?

many thanks,

5
  • Is $student_numbers a PHP variable? It looks like. Maybe you should post some code of what you already did. Commented May 17, 2011 at 14:17
  • i've just pre-constructed my array in PHP from a couple of queries. Commented May 17, 2011 at 14:19
  • with $.post() you send data from your client (JavaScript) to your server (PHP). But you already have the variable on your server. What exactly you are trying to do? Commented May 17, 2011 at 14:22
  • perform my database queries without refreshing the page basically. Commented May 17, 2011 at 14:23
  • Thats not very clear from your question. I think the answers already given should point you in the right direction. Commented May 17, 2011 at 14:25

3 Answers 3

3

Check jQuery.post(). There is an example for posting arrays.

EDITED: Example is like;

$.post("test.php", { 'choices[]': ["Jon", "Susan"] });
Sign up to request clarification or add additional context in comments.

3 Comments

ye i looked at this, but my array is already pre-constructed :S
So replace the Jon,Susan part with your array, e.g. $.post('test.php', { 'choices[]' : your_array_variable_here }
ok thanks Marc, Ill give it whirl. Does my array have to involve the delimeter , ? if that makes sense.
1

I guess, without going into great detail, the answer on you question is called JSON.

The process is easy:

Backend (PHP) Array -> encode as JSON string -> send that JSON string to the browser -> decode the JSON string as Javascript Array

1 Comment

but the issue is, its a university server and I was under the impression not all servers have JSON serialization supported, which I have no idea if this does, so I was hoping there was a different solution.
0

Check The jQuery Site and the Docs for jQuery.post()

Comments

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.