• 基础


        funSendHTTP({
            method: "POST",
            sHost: "http://localhost/20160728/ZhuCe.php",
            paraJSON: {
                "dtype":"json",
                "key":"保密啊",
                "menu":"鱼",
                "pn":"0",
                "rn":"100"
            },
            funSuccess: function (oXMLHttpRequest) {
                /*返回普通文本*/
                // oXMLHttpRequest.responseText;
                /**
                 * 返回XML
                 */
                ///*"<res><mes>...</mes></res>"*/
                // var oXML = oXMLHttpRequest.responseXML
                // oXML.getElementsByTagName("mes")[0].childNodes[0].nodeValue;
                /**
                 * 返回json文本
                 */
                var oJSON = JSON.parse(oXMLHttpRequest.responseText);
                console.log("成功",oJSON);
            },
            funFailure: function (oXMLHttpRequest) {
                console.log("失败");
            }
        });
    

      

    <?php
            /*GET请求不缓存响应*/
            header("Cache-Control:no-cache");
            /*返回的字符集规范*/
            header("Content-Type:text/html;charset=utf-8");
    
            function funGET($str){
                return  !empty($_GET[$str]) ? $_GET[$str] : null;
            }
            function funPOST($str){
                return !empty($_POST[$str]) ? $_POST[$str] : null;
            }
            function funGetResponse($str) {
                $oCurl = curl_init();
                curl_setopt($oCurl,CURLOPT_RETURNTRANSFER,1);
                curl_setopt($oCurl,CURLOPT_URL,$str);
                curl_setopt($oCurl,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);
                $oResponse = curl_exec($oCurl);
                curl_close($oCurl);
                return $oResponse;
            }
    
            $dtype= funPOST("dtype");
            $key= funPOST("key");
            $menu= funPOST("menu");
            $pn= funPOST("pn")?funPOST("pn"):"0";
            $rn= funPOST("rn");
            $menuUrl = "http://apis.juhe.cn/cook/query?dtype=".$dtype."&key=".$key."&menu=".$menu."&pn=".$pn."&rn=".$rn;
    
            $menuResponse = funGetResponse($menuUrl);
            $menuResponseEx = json_decode($menuResponse);
            /*内容规范*/
            header("Content-type:application/json");
            echo json_encode($menuResponseEx);
    
    ?>
    

      

  • 相关阅读:
    File类 文件过滤器
    LinkedList类的基本方法的用法
    Execption异常 手动和自动抛除异常
    Xshell连接Linux慢问题解决办法
    Liunx网络技术管理及进程管理
    Liunx中三种网络模式配置及Xshell连接
    LInux命令英文全称
    Liunx中fstab文件详解
    20190411RAID磁盘阵列及CentOS7系统启动流程
    20190410Linux中磁盘管理及LVM(week2day1)
  • 原文地址:https://www.cnblogs.com/WeWeZhang/p/5861379.html
Copyright © 2020-2023  润新知