zoukankan      html  css  js  c++  java
  • 自己开发中遇到的一系列小问题

      1.编码问题,中文存入mySQL数据库,出现乱码。一直不知道怎么搞定,后来在PDO链接数据库的时候设置了下编码方式

    self::$myPDO=new PDO("mysql:host=".$this->dbhost.";port=".$this->dbport.";dbname=".$this->dbname, $this->dbuser, $this->dbpwd);
    self::$myPDO->exec("set names utf8");

    既然很好的解决了这个问题。

      2.ajax请求后端接口函数,java里面有配置action,但是php里面不可以配置,每次都只可以直接请求一个PhP文件,我把action写成参数,在php文件里面在解析具体要执行类的那个函数;

    class race{
    private $id;
    private $_name;
    private $_code;
    private $content;
    /*
    public function __construct(){

    }


    //query all race list return Json type data
    public function queryAllRace(){
    $db = new DB();
    $raceSQL ='select id, name,code,content from je_race ';
    $result = $db->query($raceSQL);
    echo $result;
    }


    }
    $action=$_POST['action'];
    $race = new Race();
    if($action !=""){
    switch($action){
    case "queryAllRace":
    $race->queryAllRace();
    break;
    default:
    echo 'error no action';
    break;
    }

    }

    前端ajax

    getAllRace :function(){ //get race list
    var param ={};
    param.url ="phpsource/race.class.php";
    param.data={
    action:"queryAllRace"
    }
    param.callback = function(xhr){
    console.log(xhr);
    var data = JSON.parse(xhr.responseText);
    var html="";
    for(var i=0;i<data.length;i++){
    html += Util.rendTemplate(tempate.raceList,data[i]);
    }
    $("#racelist tbody").append(html);
    }
    Util.ajax(param);
    },

  • 相关阅读:
    HNOI2018退役记
    codeforces 960G Bandit Blues
    codeforces 933D A Creative Cutout
    tyvj1953 Normal
    loj6119 「2017 山东二轮集训 Day7」国王
    codeforces 293E Close Vertices
    bzoj1808 [Ioi2007]training 训练路径
    bzoj2219 数论之神
    bzoj4361 isn
    loj2064[HAOI2016]找相同字符
  • 原文地址:https://www.cnblogs.com/ievy/p/3771599.html
Copyright © 2011-2022 走看看