Could you use get.JSON?
http://docs.jquery.com/Ajax/jQuery.getJSON

You could of course also use post, but for quickies I use get:
$.getJSON("example.php", { name: "John", time: "2pm" }, function(json) {
     alert("JSON Data: " + json.users[3].name);
});

In the above, example.com/?name=John&time=2pm is what will be sent along.

If you are just reading data, I would use getJSON, if you are going to have your php script do updating and other things, look at.post() like you are.

My understanding of serialize is that it will convert input elements to name=value pairs. Since you already have an array, it sounds to me like you just need to convert it to a url ready format.

if you want to convert it to JSON, I believe you use serializeArray instead
http://docs.jquery.com/Ajax/serializeArray

--
Scott * If you contact me off list replace talklists@ with scott@ *

On Sep 26, 2009, at 3:44 AM, Althalos wrote:

I have an array in a Javascript/jQuery code, and I want to pass it to
a php file. It has an arbitrary number of elements in it. So I figured
I would use $.post, HOWEVER, I'm sure how I would convert my array
into a suitable data-string?

$.post("test.php", data); << what should data be when I want to pass
an entire array?

I looked around a bit on Google and I found the function serialize
which seems to do what I want. But it only works on forms and not on
arrays...

Reply via email to