Answer the question
In order to leave comments, you need to log in
AJAX + PHP gradual output?
I can't figure out how to display multiple results after sending $_Post[] request via ajax using foreach.
js only gets the first return $info; the rest is not processed.
MY CODE:
JS - OUTPUT AND SEND
$(function(){
$.ajax({
type: "POST",
url: "/proxy",
data:'xxx='+JSON.stringify(post),
dataType: 'JSON',
success: function(html){
.info.html('<div class="alert">'+html+'</div>'); }
});
});
if(isset($_POST['xxx'])){
$like = $_POST['xxx'];
$result = $op->start($like);
echo json_encode($result);
exit();
public function start ($message) {
foreach ($user as $user){
$status = $op->post($message,$user,$us);
if($status == false){
$info = "error";
}else{
$info = "ok";
}
}
return $info;
}
Answer the question
In order to leave comments, you need to log in
Rather, not the first $info, but the last one, because you are overwriting a variable in a loop.
Perhaps you wanted to write
public function start ($message) {
$info=[];
foreach ($user as $user){
$status = $op->post($message,$user,$us);
if($status == false){
$info[] = "error";
}else{
$info[] = "ok";
}
}
return $info;
}
something is wrong with you and it’s not clear what you did.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question