只能是ajax提交php读数据库,
然后ajax获取返回值,用js进行处理,然后将处理结果在传给php处理,。
思路的例子是这样:可能有错误,没测试
php:data_read.php
<?
$act=$_POST['act'];
if($act=='read'){
//read sql and return json result
//do read
echo 'ss:xx,aa:bb';
}
else if($act=='save'){
//save data to sql and return success or failed
$do_sql =0;
//do save....
if($do_sql)echo 'success';
else echo 'failed';
}
else{
echo 'error';
}
?>
html:<div id='div_test'></div>
js:
function ajax_test(params){//params='&act=read&a=selectname....'
$.ajax({
url:'data_read.php',
type:'post',
dataType:'html',
data:params,
error: function(){alert('error');},
success:function(products){
if(products!='error'){
//do read sql data
//do data process
//do ajax post
$.ajax({
url:'data_read.php',
type:'post',
dataType:'html',
data:params2,
error: function(){alert('error');},
success:function(products){
if(products!='success'){
//ok
}
// else failed
}
});
}
// else failed
}
});
}
温馨提示:答案为网友推荐,仅供参考