How to load previous or next attachment with jquery ?

@milo thanks ! i used a technique found on the page you sent.

it’s almost working.

I added this at the end of the previous single.php code :

array_unshift($attachments_list,"");
wp_enqueue_script('myscript');
wp_localize_script('myscript', 'attachments_list', $attachments_list);

To work, this code must be called before wp_head().
Then, for a mysterious reason, the first element (with the index 0) is printed after the JS array in the html head. That’s why i had to unshift an empty string in the array before to send it with wp_localize_script. 

Last thing:

var count = attachments_list.length;

is undefined. Everything is working fine when i replace count with a number, i can even access to the elements of the array with attachments_list[index], but the length of the array is undefined.

any idea about this ?
thank you