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;  

    ?>
  • 相关阅读:
    [转]责任链模式
    spring中常见注解描述
    [转]外观模式
    [转]策略模式
    分布式事务实践
    SpringBoot入门
    服务器性能调优
    kvm qemu内幕介绍
    xen 保存快照的实现之 —— device model 状态保存
    xen hypercall 的应用层实现
  • 原文地址:https://www.cnblogs.com/hailexuexi/p/14420263.html
Copyright © 2011-2022 走看看