Вопрос

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