How does php return variables + assemble html to ajaxfunction & nbsp; html ($ select, $ name) {global & nbsp; $ pagecon; $ a1; $ b2; $ result; $ result. & lt; ul & nbsp; & gt; while ($ row $ select-& gt; fetch: How does php return variables + assemble html to ajax?
Function html ($ select, $ name ){
Global $ pagecon;
$ A = '1 ';
$ B = '2 ';
$ Result = '';
$ Result. ='
';
While ($ row = $ select-> fetch ()){
$ Result. ='
- ';
$ Result. ='
';
$ Result. ='
'. $ Pagecon .'
';
Return $ result, $ a, $ B;
}
$ A, $ B, and an assembled $ result html are returned to ajax. if json is not used
Share: More
------ Solution --------------------
return "$result,$a,$b";
success:function(json){
a = json.split(',');
------ Solution --------------------
Function html ($ select, $ name ){
Global $ pagecon;
$ A = '1 ';
$ B = '2 ';
$ Result = '';
$ Result. ='
';
While ($ row = $ select-> fetch ()){
$ Result. ='
- ';
$ Result. ='
';
$ Result. ='
'. $ Pagecon .'
';
Return $ result. '--'. $ a. '--'. $ B; // use -- to connect and return
}
Function getData (page ){
Alert ('OK ');
$. Ajax ({
Type: 'post ',
Url: 'Action/test. php ',
Data: {'pagenum': page-1 },
BeforeSend: function (){
$ ("# Sss ul"). append ("Loading...");
},
Success: function (json ){
Var arr = json. split ('--');
$ ("# Sss ul"). empty ();
Result = arr ['0'] // Get the variable from php $ result
Total = arr ['0'] // Get the variable from php $
PageSize = // Get the variable $ B from php
$ ("P # sss" pai.html (data );
},
Complete: function () {// generate a page entry
GetPageBar ();
},
Error: function (){
Alert ("data loading failed ");
}
});
}
Hope to help you!