js代码:
<script type="text/javascript"> $(function(){ /* var input = "<input type='text' value=''/>";*/ $("#btn-edit").click(function(){ /*$("td[title=tag]").append(input);*/ var articleid = $('#articleid').val(); var allvisit = $('#allvisit').val(); var monthvisit = $('#monthvisit').val(); var weekvisit = $('#weekvisit').val(); var allvote = $('#allvote').val(); var monthvote = $('#monthvote').val(); var weekvote = $('#weekvote').val(); var goodnum = $('#goodnum').val(); $.post("indexModify.PHP",{ 'articleid':articleid,'allvisit': allvisit,'monthvisit':monthvisit,'weekvisit':weekvisit,'allvote':allvote,'monthvote':monthvote,'weekvote':weekvote,'goodnum':goodnum },function(msg){ alert("修改成功"); //接收PHP返回的值并处理 var msgobj = eval("("+msg+")"); for(var key in msgobj){ var item = msgobj[key]; alert(item); } } ); }); }); </script>
<?PHP $MysqLi = new MysqLi('localhost','root','localhost'); $MysqLi->query("set names utf8"); /*if($_SERVER['REQUEST_METHOD']=='POST'){ if(isset($_POST["submit"])){*/ $articleid = intval($_POST['articleid']); $allvisit = intval($_POST['allvisit']); $monthvisit = intval($_POST['monthvisit']); $weekvisit = intval($_POST['weekvisit']); $allvote = intval($_POST['allvote']); $monthvote = intval($_POST['monthvote']); $weekvote = intval($_POST['weekvote']); $goodnum = intval($_POST['goodnum']); /*var_dump($goodnum); echo $goodnum;*/ $sql = "update jieqi_article_article set allvisit='$allvisit',monthvisit='$monthvisit',weekvisit='$weekvisit',allvote='$allvote',monthvote='$monthvote',weekvote='$weekvote',goodnum='$goodnum'where articleid=$articleid"; $query = $MysqLi->query($sql); if ($query) { $sql = "select allvisit,monthvisit,weekvisit,allvote,monthvote,weekvote,goodnum from jieqi_article_article where articleid = $articleid"; $result = $MysqLi->query($sql); $numrows = $result->fetch_all(MysqL_ASSOC); /*var_dump($numrows);*/ $list=array("allvisit"=>$numrows[0]["allvisit"],"monthvisit"=>$numrows[0]["monthvisit"],"weekvisit"=>$numrows[0]["weekvisit"],"allvote"=>$numrows[0]["allvote"],"monthvote"=>$numrows[0]["monthvote"],"weekvote"=>$numrows[0]["weekvote"],"goodnum"=>$numrows[0]["goodnum"]); echo json_encode($list);//返回json数据类型的值给ajax