zoukankan      html  css  js  c++  java
  • 前端ajax用json方式请求 后端php 用 $GLOBALS['HTTP_RAW_POST_DATA'] 取值

           //参数--------------------------------------
                var params = {};
                params['module'] = "ai";
                params['action'] = "nextAiNode";
                params['apiVersion'] = "1.0";
                params['userId'] = "";
                params['sessionId'] = "";
                params['token'] = "";
                params['time'] = "";
                params['callerId'] = "13977666666";
                params['channelId'] = "1";
    
                params['para'] = {
                    "event":"sessionStart",
                    "asrText":"" 
                };
                //请求------------------------------
                $.ajax({
                    type: "POST",
                    url: "../webApi.php",
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(params), 
                    dataType: "json",
                    success:function (message) {
                        //alert("提交成功"+JSON.stringify(message));
                        $("#div_msg").html(JSON.stringify(message));         
                        
                    },
                    error:function (message) {
                        alert("提交失败"+JSON.stringify(message));
                    }
                }); 

    注意:   data: JSON.stringify(params),   中的 JSON.stringify() 方非常重要,如果没有则后端会取不到值。

    php端

    <?php
    //获得post的json数据,
    $postJson = json_decode($GLOBALS['HTTP_RAW_POST_DATA']);
    //获得event参数
    $eventName=$postJson->para->event;
    $asrText=$postJson->para->asrText;    
     
    $module=$postJson->module;
    $action=$postJson->action;
    $projectName=$postJson->projectName;    
    $processName=$postJson->processName;    
    $nodeName=$postJson->nodeName;    
    $callerId=$postJson->callerId;  

    ?>
  • 相关阅读:
    Using Subversion and ViewCVS on Solaris 10
    Solaris开放源代码了!
    小笨霖英语笔记本(0)
    How to start CDE/JDS with xinit command
    英译汉练习:Solaris 10进入Linux领地
    UNIX/LINUX 平台可执行文件格式分析
    小笨霖英语笔记本(2)
    小笨霖英语笔记本(3)
    小笨霖英语笔记本(1)
    魔鬼城雅丹地貌
  • 原文地址:https://www.cnblogs.com/hailexuexi/p/14420263.html
Copyright © 2011-2022 走看看