문제

I'm ajaxing an array of images from a file with php opendir function. It works in-order locally but spits out randomly when I upload it on my server. I thought maybe because I'm not ordering it personally it's doing this. I tried using the natsort() on my array before I send it back with JSON_ENCODE but it doesn't work because it's returning an object (and it's still in the wrong order just numbered). I get this locally from console.log():

 ["01_cul_project_01.jpg", "02_cor_project_02.jpg", "03_cul_project_03.jpg",...]

And this from my server from console.log():

 0: "07_cor_project_07.jpg"
 1: "08_cul_project_08.jpg"
 2: "15_cor_project_15.jpg"
 ...

Are there any better ways of ordering the array? Any suggestions in how to fix this? Cheers in advance for your help.

EDIT 01 - SOLUTION

Sort the array after JSON callback with javascript:

 var blah = array("3","1","5"...);
 blah.sort();
도움이 되었습니까?

해결책

Sort the array after JSON callback with javascript:

var blah = ["3", "1", "5"...];
blah.sort();

gives

["1", "2", "3"...]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top