문제

Context:

I want to get multiple values from my database with ajax and php. I see previous post about this (like How to get multiple responses from PHP file via AJAX? ) but all the time it seems the number of values is already known.

I have to return unknown number of values because i dont know how many roxs will be selected.

Question:

Are they tricks to get unknown number of values with ajax or should i put data in different arrays and then return them?

Thanks for your answer.

도움이 되었습니까?

해결책

You should use JSON.

//PHP side
echo json_encode([$var1, $var2, $var3]);

//JS side
var array = JSON.parse(xhr.responseText);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top