I have a PHP file which is responding to a jQuery Ajax call with dataType: 'HTML',. The PHP looks like
if( $result->num_rows > 0 ){
....
echo '<p>There are some user already </p>';
}
else{
echo '<p>List is empty </p>';
}
this is working fine on my JS side like
ajaxcall.done(function(data) {
$('#call-result').html(data);
});
but I also need to add some business logic on client side to the page by passing a Boolean flag from the server to the JS. How can I pass the true false along with HTML snippet from the server to client?
json_encode()to create a JSON responsedatainto$('#call-result').html(data);data.resultcan be your boolean anddata.htmlcan be your HTML, for example. I believe jQuery will automatically parse the JSON response into an object.