S
S
Sergey Miller2021-06-16 22:07:36
PHP
Sergey Miller, 2021-06-16 22:07:36

How to determine the desired response from php json_encode in jq?

in php, when all checks passed successfully, try to send response

echo json_encode(array("success" => $result, "pagi" => $pagi), JSON_UNESCAPED_UNICODE);


That is, give an array of $result and $pagi

to jq

$.ajax({
url: '...',
type: 'post',
dataType: 'json',
data: ...,
success: function(json){

if(typeof json.success !== 'undefined'){

$(document).find('.loadItemsHere').html(json.success);
}

else if(typeof json.error !== 'undefined'){
alert(json.error);
} 

else if(typeof json.pagi !== 'undefined'){

$(document).find('.loadItemsHere').after(json.pagi);
}

}, error: ....


If output separately
echo json_encode(["success" => $result], JSON_UNESCAPED_UNICODE);

or
echo json_encode(["pagi" => $pagi], JSON_UNESCAPED_UNICODE);

Then everything comes as it should, but passing two parameters only success comes

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Spartak (Web-StyleStudio), 2021-06-16
@blackseabreathe


if(typeof json.success !== 'undefined'){
  $(document).find('.loadItemsHere').html(json.success);
}
else if

You receive all the parameters, but only one is displayed, because the code is not executed beyond this condition!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question