zoukankan      html  css  js  c++  java
  • 基础

        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);
    
    ?>
    

      

  • 相关阅读:
    软件工程--团队作业3
    软件工程--团队作业2
    软件工程第二次作业---结对编程
    软件工程第一次作业补充
    软件工程第一次作业
    用Use Case获取需求的方法是否有什么缺陷,还有什么地方需要改进?
    买卖股票的最佳时机
    爬楼梯
    删除排序数组中的重复数字
    1500802035王叔文
  • 原文地址:https://www.cnblogs.com/WeWeZhang/p/5861379.html
Copyright © 2011-2022 走看看