Example of js and PHP communicating with json data

  • 2020-03-30 02:30:24
  • OfStack

Js and PHP communicate through json data

Example:

PHP file
 
<?php 
echo json_encode(array(array( 
'liaotiantiao'=>$liaotiantiao, 
'liaotiank'=>$liaotiank, 
'chatuserid'=>$chatuserid, 
'chattouserid'=>$chattouserid 
))); 
?> 

The HTML file
 
$(document).ready(function(){ 
//Default bar chat bar chat box status
$.post('/index.php/chat/morenltt',{},function(val){ 
var obj=eval(val); 
alert(obj[0].chatuserid); 
}); 
}); 

Related articles: